Method: Hash#inject_into_empty
- Defined in:
- lib/enumerate_hash_values/core_extensions/hash.rb
#inject_into_empty(hash_class = self.class, options = {}) ⇒ Object
Shortcut to inject into an empty hash.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/enumerate_hash_values/core_extensions/hash.rb', line 67 def inject_into_empty(hash_class = self.class, = {}) raise ArgumentError.new("#{hash_class} is not a Hash") unless hash_class.ancestors.include?(Hash) # If not explicitly specified, copy traits into the new hash if it is of # the same class. copy_traits = .has_key?(:copy_traits) ? [:copy_traits] : (hash_class == self.class) = {} [:traits_from] = self if copy_traits new_hash = hash_class.new_empty() inject(new_hash) do |hash, key_value_pair| yield hash, key_value_pair end end |