Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/fusuma/hash_support.rb
Overview
Patch to hash
Instance Method Summary collapse
-
#deep_merge(other_hash, &block) ⇒ Object
activesupport-5.2.0/lib/active_support/core_ext/hash/deep_merge.rb.
-
#deep_merge!(other_hash, &block) ⇒ Object
Same as
deep_merge
, but modifiesself
. - #deep_stringify_keys ⇒ Object
-
#deep_symbolize_keys ⇒ Object
activesupport-4.1.1/lib/active_support/core_ext/hash/keys.rb.
- #deep_transform_keys(&block) ⇒ Object
-
#deep_transform_values(&block) ⇒ Object
activesupport/lib/active_support/core_ext/hash/deep_transform_values.rb.
Instance Method Details
#deep_merge(other_hash, &block) ⇒ Object
activesupport-5.2.0/lib/active_support/core_ext/hash/deep_merge.rb
6 7 8 |
# File 'lib/fusuma/hash_support.rb', line 6 def deep_merge(other_hash, &block) dup.deep_merge!(other_hash, &block) end |
#deep_merge!(other_hash, &block) ⇒ Object
Same as deep_merge
, but modifies self
.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fusuma/hash_support.rb', line 11 def deep_merge!(other_hash, &block) merge!(other_hash) do |key, this_val, other_val| if this_val.is_a?(Hash) && other_val.is_a?(Hash) this_val.deep_merge(other_val, &block) elsif block block.call(key, this_val, other_val) else other_val end end end |
#deep_stringify_keys ⇒ Object
23 24 25 |
# File 'lib/fusuma/hash_support.rb', line 23 def deep_stringify_keys deep_transform_keys(&:to_s) end |
#deep_symbolize_keys ⇒ Object
activesupport-4.1.1/lib/active_support/core_ext/hash/keys.rb
28 29 30 31 32 33 34 |
# File 'lib/fusuma/hash_support.rb', line 28 def deep_symbolize_keys deep_transform_keys do |key| key.to_sym rescue key end end |
#deep_transform_keys(&block) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/fusuma/hash_support.rb', line 36 def deep_transform_keys(&block) result = {} each do |key, value| result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value end result end |
#deep_transform_values(&block) ⇒ Object
activesupport/lib/active_support/core_ext/hash/deep_transform_values.rb
45 46 47 |
# File 'lib/fusuma/hash_support.rb', line 45 def deep_transform_values(&block) _deep_transform_values_in_object(self, &block) end |