Class: Util::Store
- Inherits:
-
Object
- Object
- Util::Store
- Defined in:
- ../lib/store.rb
Overview
Population marshalling. Store class saves or loads the content of the population.
Instance Attribute Summary (collapse)
-
- (Object) filename
The path to the store file.
Instance Method Summary (collapse)
-
- (Store) initialize(filename = nil)
constructor
Set the path to the file.
-
- (Object) load
Load the population using Marshal.load and returns it to the caller.
-
- (Object) save(population)
Save the population using Marshal.dump.
Constructor Details
- (Store) initialize(filename = nil)
Set the path to the file.
9 10 11 |
# File '../lib/store.rb', line 9 def initialize filename=nil @filename = filename end |
Instance Attribute Details
- (Object) filename
The path to the store file.
14 15 16 |
# File '../lib/store.rb', line 14 def filename @filename end |
Instance Method Details
- (Object) load
Load the population using Marshal.load and returns it to the caller. If loading fails, the nil is returned.
23 24 25 26 |
# File '../lib/store.rb', line 23 def load return nil unless FileTest.readable? @filename File.open( @filename ) { |f| return Marshal.load(f) } end |
- (Object) save(population)
Save the population using Marshal.dump
17 18 19 |
# File '../lib/store.rb', line 17 def save population File.open( @filename, "w" ) { |f| Marshal.dump(population, f) } end |