Method: Enumerable#hashify

Defined in:
lib/jinx/helpers/enumerable.rb

#hashifyHash

Returns a new Hash generated from this Enumerable and an optional value generator block. This Enumerable contains the Hash keys. If the value generator block is given to this method then the block is called with each enumerated element as an argument to generate the associated hash value. If no block is given, then the values are nil.

Examples:

[1, 2, 3].hashify { |item| item.modulo(2) } #=> { 1 => 1, 2 => 0, 3 => 1 }
[:a].hashify #=> { :a => nil }

Returns:



14
15
16
17
18
# File 'lib/jinx/helpers/enumerable.rb', line 14

def hashify
  hash = {}
  each { |item| hash[item] = yield item if block_given? }
  hash
end