class MAndM::Preferences
Attributes
hash[R]
preferences_path[R]
Public Class Methods
new(name)
click to toggle source
# File lib/m_and_m/preferences.rb, line 4 def initialize name @preferences_path = File.join File.expand_path('~'), name if File.exists? preferences_path @hash = YAML.load_file preferences_path else @hash = {} end end
Public Instance Methods
[](key)
click to toggle source
# File lib/m_and_m/preferences.rb, line 21 def [] key hash[key] end
[]=(key, value)
click to toggle source
# File lib/m_and_m/preferences.rb, line 25 def []= key, value hash[key] = value persist end
ask(key, prompt)
click to toggle source
# File lib/m_and_m/preferences.rb, line 13 def ask key, prompt unless hash[key] print "#{prompt} ? " self[key] = $stdin.gets.chomp end self[key] end
persist()
click to toggle source
# File lib/m_and_m/preferences.rb, line 30 def persist File.open(preferences_path, 'w') {|f| f.puts hash.to_yaml} end