Class: Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/rubysketch/solitaire/common/settings.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Settings

Returns a new instance of Settings.



3
4
5
6
# File 'lib/rubysketch/solitaire/common/settings.rb', line 3

def initialize(path)
  @path = path or raise 'invalid path'
  @hash = load path
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/rubysketch/solitaire/common/settings.rb', line 21

def [](key)
  hash[key]
end

#[]=(key, value) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rubysketch/solitaire/common/settings.rb', line 13

def []=(key, value)
  if value != hash[key]
    hash[key] = value
    save @path
  end
  value
end

#clearObject



8
9
10
11
# File 'lib/rubysketch/solitaire/common/settings.rb', line 8

def clear()
  hash.clear
  save @path
end

#to_jsonObject



25
26
27
# File 'lib/rubysketch/solitaire/common/settings.rb', line 25

def to_json()
  hash.to_json
end