Module: Darthjee::CoreExt::Hash::Transformable
- Included in:
- Darthjee::CoreExt::Hash
- Defined in:
- lib/darthjee/core_ext/hash/transformable.rb
Instance Method Summary collapse
-
#exclusive_merge(other) ⇒ ::Hash
Merges both hashes not adding keys that don’t exist in the original hash.
-
#exclusive_merge!(other) ⇒ ::Hash
Merges both hashes not adding keys that don’t exist in the original hash.
-
#map_to_hash {|key, value| ... } ⇒ Object
Run map block where each pair key, value is mapped to a new value to be assigned in the same key on the returned hash.
-
#squash ⇒ ::Hash
Squash the hash so that it becomes a single level hash merging the keys of outter and inner hashes.
-
#to_deep_hash(separator = '.') ⇒ ::Hash
Creates a new hash of multiple levels from a one level hash.
Instance Method Details
#exclusive_merge(other) ⇒ ::Hash
Merges both hashes not adding keys that don’t exist in the original hash
20 21 22 |
# File 'lib/darthjee/core_ext/hash/transformable.rb', line 20 def exclusive_merge(other) dup.exclusive_merge!(other) end |
#exclusive_merge!(other) ⇒ ::Hash
Merges both hashes not adding keys that don’t exist in the original hash
37 38 39 |
# File 'lib/darthjee/core_ext/hash/transformable.rb', line 37 def exclusive_merge!(other) merge!(other.slice(*keys)) end |
#map_to_hash {|key, value| ... } ⇒ Object
Run map block where each pair key, value is mapped to a new value to be assigned in the same key on the returned hash
59 60 61 |
# File 'lib/darthjee/core_ext/hash/transformable.rb', line 59 def map_to_hash(&block) Hash::ToHashMapper.new(self).map(&block) end |
#squash ⇒ ::Hash
Squash the hash so that it becomes a single level hash merging the keys of outter and inner hashes
This operation is the oposite of #to_deep_hash
92 93 94 |
# File 'lib/darthjee/core_ext/hash/transformable.rb', line 92 def squash Hash::Squasher.squash(self) end |
#to_deep_hash(separator = '.') ⇒ ::Hash
Creates a new hash of multiple levels from a one level hash
this operation is the oposite from #squash
131 132 133 |
# File 'lib/darthjee/core_ext/hash/transformable.rb', line 131 def to_deep_hash(separator = '.') Hash::DeepHashConstructor.new(separator).deep_hash(self) end |