| Module | Aquarium::Utils::HashUtils |
| In: |
lib/aquarium/utils/hash_utils.rb
|
Convert the input item or array into a hash with a nil value or the result of evaluating the optional input block, which takes a single argument for the item. If the input is already a hash, it is returned unmodified.
# File lib/aquarium/utils/hash_utils.rb, line 11
11: def make_hash item_or_array_or_hash
12: return {} if item_or_array_or_hash.nil?
13: return strip_nil_keys(item_or_array_or_hash) if item_or_array_or_hash.kind_of?(Hash)
14: hash = {}
15: [item_or_array_or_hash].flatten.each do |element|
16: unless element.nil?
17: hash[element] = block_given? ? yield(element) : nil
18: end
19: end
20: hash
21: end