Class: Darthjee::CoreExt::Hash::Squasher Private
- Defined in:
- lib/darthjee/core_ext/hash/squasher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
class responsible for squashing a hash
Instance Attribute Summary collapse
- #joiner ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(joiner = '.') ⇒ Squasher
constructor
private
A new instance of Squasher.
-
#squash(hash) ⇒ ::Hash
private
Squash a hash creating a new hash.
Constructor Details
#initialize(joiner = '.') ⇒ Squasher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Squasher.
21 22 23 |
# File 'lib/darthjee/core_ext/hash/squasher.rb', line 21 def initialize(joiner = '.') @joiner = joiner end |
Instance Attribute Details
#joiner ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 |
# File 'lib/darthjee/core_ext/hash/squasher.rb', line 18 def joiner @joiner end |
Instance Method Details
#squash(hash) ⇒ ::Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Squash a hash creating a new hash
Squash the hash so that it becomes a single level hash merging the keys of outter and inner hashes
70 71 72 73 74 75 76 77 78 |
# File 'lib/darthjee/core_ext/hash/squasher.rb', line 70 def squash(hash) hash.keys.each do |key| next unless hash[key].is_any?(Hash, Array) value = hash.delete(key) add_value_to_hash(hash, key, value) end hash end |