Class: Settings
- Inherits:
-
Object
- Object
- Settings
- Defined in:
- lib/game_2d/storage.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(name) ⇒ Settings
constructor
A new instance of Settings.
- #save ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Settings
Returns a new instance of Settings.
27 28 29 30 |
# File 'lib/game_2d/storage.rb', line 27 def initialize(name) @name = name @values = File.exist?(name) ? JSON.parse(IO.read(name)).fix_keys : {} end |
Instance Method Details
#[](key) ⇒ Object
37 |
# File 'lib/game_2d/storage.rb', line 37 def [](key); @values[key]; end |
#[]=(key, value) ⇒ Object
38 |
# File 'lib/game_2d/storage.rb', line 38 def []=(key, value); @values[key] = value; end |
#empty? ⇒ Boolean
39 |
# File 'lib/game_2d/storage.rb', line 39 def empty?; @values.empty?; end |
#save ⇒ Object
32 33 34 35 |
# File 'lib/game_2d/storage.rb', line 32 def save puts "Writing to #{self}" File.open(@name, 'w') {|f| f.write(@values.to_json) } end |
#to_s ⇒ Object
41 |
# File 'lib/game_2d/storage.rb', line 41 def to_s; "Settings(#{@name})"; end |