Method: Array#to_hash

Defined in:
lib/extlib/array.rb

#to_hashHash

Transforms an Array of key/value pairs into a Hash

This is a better idiom than using Hash in Ruby 1.8.6 because it is not possible to limit the flattening to a single level.

Returns:

  • A Hash where each entry in the Array is turned into a key/value

API:

  • public



16
17
18
19
20
# File 'lib/extlib/array.rb', line 16

def to_hash
  h = {}
  each { |k,v| h[k] = v }
  h
end