Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/compute_unit/monkey_patches.rb
Instance Method Summary collapse
Instance Method Details
#stringify_keys ⇒ Object
66 67 68 69 70 71 |
# File 'lib/compute_unit/monkey_patches.rb', line 66 def stringify_keys each_with_object({}) do |(key, value), hash| value = value.stringify_keys if value.is_a?(Hash) hash[key.to_s] = value end end |
#symbolize_keys(&select) ⇒ Object
73 74 75 |
# File 'lib/compute_unit/monkey_patches.rb', line 73 def symbolize_keys(&select) dup.symbolize_keys!(&select) end |
#symbolize_keys!(&select) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/compute_unit/monkey_patches.rb', line 77 def symbolize_keys!(&select) if select keys.each do |key| next unless select[key] new_key = (begin key.to_sym rescue StandardError key.to_s.to_sym end) self[new_key] = delete(key) end else keys.each do |key| new_key = (begin key.to_sym rescue StandardError key.to_s.to_sym end) self[new_key] = delete(key) end end self end |