Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/postage/extensions.rb
Instance Method Summary collapse
-
#instance_variables_set_to(object) ⇒ Object
Set instance variables by key and value only if object respond to access method for variable.
-
#symbolize_keys ⇒ Object
Only symbolize all keys, including all key in sub-hashes.
Instance Method Details
#instance_variables_set_to(object) ⇒ Object
Set instance variables by key and value only if object respond to access method for variable.
17 18 19 20 21 22 |
# File 'lib/postage/extensions.rb', line 17 def instance_variables_set_to(object) collect do |variable, value| object.instance_variable_set("@#{variable}", value) if object.respond_to? variable end object end |
#symbolize_keys ⇒ Object
Only symbolize all keys, including all key in sub-hashes.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/postage/extensions.rb', line 4 def symbolize_keys self.inject({}) do |hash, (key, value)| hash[key.to_sym] = if value.kind_of? Hash value.symbolize_keys else value end hash end end |