Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/doing/hash.rb
Overview
Hash helpers
Instance Method Summary collapse
-
#deep_freeze ⇒ description_of_the_return_value
Freeze all values in a hash.
- #deep_freeze! ⇒ Object
-
#stringify_keys ⇒ Object
Turn all keys into string.
-
#symbolize_keys ⇒ Object
Turn all keys into symbols.
Instance Method Details
#deep_freeze ⇒ description_of_the_return_value
Freeze all values in a hash
11 12 13 |
# File 'lib/doing/hash.rb', line 11 def deep_freeze map { |k, v| v.is_a?(Hash) ? v.deep_freeze : v.freeze }.freeze end |
#deep_freeze! ⇒ Object
15 16 17 |
# File 'lib/doing/hash.rb', line 15 def deep_freeze! replace deep_freeze end |
#stringify_keys ⇒ Object
Turn all keys into string
Return a copy of the hash where all its keys are strings
22 23 24 |
# File 'lib/doing/hash.rb', line 22 def stringify_keys each_with_object({}) { |(k, v), hsh| hsh[k.to_s] = v.is_a?(Hash) ? v.stringify_keys : v } end |
#symbolize_keys ⇒ Object
Turn all keys into symbols
27 28 29 |
# File 'lib/doing/hash.rb', line 27 def symbolize_keys each_with_object({}) { |(k, v), hsh| hsh[k.to_sym] = v.is_a?(Hash) ? v.symbolize_keys : v } end |