Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/ckick/hash.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#array_aware_deep_symbolize_keys ⇒ Object
transforms each String-key to Symbol-key.
-
#array_aware_deep_transform_keys(&block) ⇒ Object
transforms keys recursively *
block
- transform operation. -
#without(*keys) ⇒ Object
copy of the hash without pairs of
keys
. -
#without!(*keys) ⇒ Object
removes each pair of
keys
.
Instance Method Details
#array_aware_deep_symbolize_keys ⇒ Object
transforms each String-key to Symbol-key
26 27 28 |
# File 'lib/ckick/hash.rb', line 26 def array_aware_deep_symbolize_keys array_aware_deep_transform_keys { |key| key.to_sym rescue key } end |
#array_aware_deep_transform_keys(&block) ⇒ Object
transforms keys recursively
-
block
- transform operation
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ckick/hash.rb', line 11 def array_aware_deep_transform_keys(&block) result = {} each do |key, value| new_key = yield(key) if value.is_a?(Hash) || value.is_a?(Array) result[new_key] = value.array_aware_deep_transform_keys(&block) else result[new_key] = value end end result end |
#without(*keys) ⇒ Object
copy of the hash without pairs of keys
31 32 33 |
# File 'lib/ckick/hash.rb', line 31 def without(*keys) dup.without!(*keys) end |
#without!(*keys) ⇒ Object
removes each pair of keys
36 37 38 |
# File 'lib/ckick/hash.rb', line 36 def without!(*keys) reject! { |key| keys.include?(key) } end |