Module: Agrippa::MutableHash::InstanceMethods
- Defined in:
- lib/agrippa/mutable_hash.rb
Instance Method Summary collapse
- #__apply_default_state ⇒ Object
- #chain(updates) ⇒ Object
- #fetch(key, default = nil) ⇒ Object
- #initialize(state = nil) ⇒ Object
- #store(key, value) ⇒ Object
Instance Method Details
#__apply_default_state ⇒ Object
64 65 66 67 68 69 |
# File 'lib/agrippa/mutable_hash.rb', line 64 def __apply_default_state return(self) unless @state.nil? @state = default_state if respond_to?(:default_state) @state ||= {} self end |
#chain(updates) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/agrippa/mutable_hash.rb', line 48 def chain(updates) raise(ArgumentError, "#set requires a Hash") \ unless updates.respond_to?(:each_pair) updates.each_pair { |key, value| store(key, value) } self end |
#fetch(key, default = nil) ⇒ Object
60 61 62 |
# File 'lib/agrippa/mutable_hash.rb', line 60 def fetch(key, default = nil) @state.fetch(key.to_sym, default) end |
#initialize(state = nil) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/agrippa/mutable_hash.rb', line 41 def initialize(state = nil) raise(ArgumentError, "#{self.class}#new requires a hash.") \ unless (state.nil? or state.respond_to?(:each_pair)) __apply_default_state chain(state) if (state.respond_to?(:each_pair)) end |
#store(key, value) ⇒ Object
55 56 57 58 |
# File 'lib/agrippa/mutable_hash.rb', line 55 def store(key, value) @state.store(key.to_sym, value) self end |