Module: Gitlab::Utils::MergeHash
Instance Method Summary collapse
-
#crush(array_or_hash) ⇒ Object
This extracts all keys and values from a hash into an array.
-
#merge(elements) ⇒ Object
Deep merges an array of hashes.
Instance Method Details
#crush(array_or_hash) ⇒ Object
This extracts all keys and values from a hash into an array
{ hello: “world”, this: { crushes: [“an entire”, “hash”] } }
> [:hello, “world”, :this, :crushes, “an entire”, “hash”]
40 41 42 43 44 45 46 |
# File 'lib/gitlab/utils/merge_hash.rb', line 40 def crush(array_or_hash) if array_or_hash.is_a?(Array) crush_array(array_or_hash) else crush_hash(array_or_hash) end end |
#merge(elements) ⇒ Object
Deep merges an array of hashes
- { hello: [“world”
-
},
{ hello: "Everyone" },
{ hello: { greetings: ['Bonjour', 'Hello', 'Hallo', 'Dzien dobry'] } },
"Goodbye", "Hallo"]
> [
{
hello:
[
"world",
"Everyone",
{ greetings: ['Bonjour', 'Hello', 'Hallo', 'Dzien dobry'] }
]
},
"Goodbye"
]
26 27 28 29 30 31 32 33 34 |
# File 'lib/gitlab/utils/merge_hash.rb', line 26 def merge(elements) merged, *other_elements = elements other_elements.each do |element| merged = merge_hash_tree(merged, element) end merged end |