Class: Bandicoot::SaveFile

Inherits:
Object
  • Object
show all
Defined in:
lib/bandicoot/save_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, save_points = nil) ⇒ SaveFile

Returns a new instance of SaveFile.



18
19
20
21
# File 'lib/bandicoot/save_file.rb', line 18

def initialize(file, save_points=nil)
  @file = file
  @save_points = save_points
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/bandicoot/save_file.rb', line 5

def file
  @file
end

#save_pointsObject (readonly)

Returns the value of attribute save_points.



5
6
7
# File 'lib/bandicoot/save_file.rb', line 5

def save_points
  @save_points
end

Class Method Details

.continue(filename) ⇒ Object



11
12
13
14
15
16
# File 'lib/bandicoot/save_file.rb', line 11

def self.continue(filename)
  file = File.open(filename, "r+")
  save_points = read_save_points(file)
  file.seek(0, IO::SEEK_END)
  new(file, save_points)
end

.create(filename) ⇒ Object



7
8
9
# File 'lib/bandicoot/save_file.rb', line 7

def self.create(filename)
  new(File.open(filename, "w"))
end

Instance Method Details

#closeObject



28
29
30
# File 'lib/bandicoot/save_file.rb', line 28

def close
  file.close
end

#write(key, retval) ⇒ Object



23
24
25
26
# File 'lib/bandicoot/save_file.rb', line 23

def write(key, retval)
  file.write([key, retval].to_msgpack)
  #file.fsync
end