Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/fusuma/hash_support.rb
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 : () -> Hash[Symbol, untyped].
-
#deep_transform_keys(&block) ⇒ Object
: [T] () { (untyped) -> T } -> Hash[T, untyped].
-
#deep_transform_values(&block) ⇒ Object
activesupport/lib/active_support/core_ext/hash/deep_transform_values.rb : () { (untyped) -> untyped } -> Hash[untyped, untyped].
Instance Method Details
#deep_merge(other_hash, &block) ⇒ Object
activesupport-5.2.0/lib/active_support/core_ext/hash/deep_merge.rb
7 8 9 |
# File 'lib/fusuma/hash_support.rb', line 7 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.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fusuma/hash_support.rb', line 12 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
24 25 26 |
# File 'lib/fusuma/hash_support.rb', line 24 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 : () -> Hash[Symbol, untyped]
30 31 32 33 34 35 36 |
# File 'lib/fusuma/hash_support.rb', line 30 def deep_symbolize_keys deep_transform_keys do |key| key.to_sym rescue key end end |
#deep_transform_keys(&block) ⇒ Object
: [T] () { (untyped) -> T } -> Hash[T, untyped]
39 40 41 42 43 44 45 |
# File 'lib/fusuma/hash_support.rb', line 39 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 : () { (untyped) -> untyped } -> Hash[untyped, untyped]
49 50 51 |
# File 'lib/fusuma/hash_support.rb', line 49 def deep_transform_values(&block) _deep_transform_values_in_object(self, &block) end |