Module: Hashie::Extensions::Coercion::InstanceMethods
- Defined in:
- lib/hashie/extensions/coercion.rb
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #custom_writer(key, value, convert = true) ⇒ Object
- #replace(other_hash) ⇒ Object
Instance Method Details
#[]=(key, value) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hashie/extensions/coercion.rb', line 10 def []=(key, value) into = self.class.key_coercion(key) || self.class.value_coercion(value) if value && into if into.respond_to?(:coerce) value = into.coerce(value) else value = into.new(value) end end super(key, value) end |
#custom_writer(key, value, convert = true) ⇒ Object
24 25 26 |
# File 'lib/hashie/extensions/coercion.rb', line 24 def custom_writer(key, value, convert = true) self[key] = value end |
#replace(other_hash) ⇒ Object
28 29 30 31 32 |
# File 'lib/hashie/extensions/coercion.rb', line 28 def replace(other_hash) (keys - other_hash.keys).each { |key| delete(key) } other_hash.each { |key, value| self[key] = value } self end |