Module: Enumerable

Defined in:
lib/iron/extensions/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#convert_to_hash(init_val = nil) ⇒ Object

Converts an enumerable into a hash, by accepting an initial value or a block to compute the value for a given key.



5
6
7
8
9
10
11
# File 'lib/iron/extensions/enumerable.rb', line 5

def convert_to_hash(init_val = nil)
  hash = {}
  self.each do |key|
    hash[key] = block_given? ? yield(key) : init_val
  end
  hash
end