Module: DataMapper::Ext::Array

Defined in:
lib/dm-core/support/ext/array.rb

Class Method Summary collapse

Class Method Details

.to_hash(array) ⇒ Hash

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.

Parameters:

  • array (Array)

    The array of key/value pairs to transform.

Returns:

  • (Hash)

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



16
17
18
19
20
# File 'lib/dm-core/support/ext/array.rb', line 16

def self.to_hash(array)
  h = {}
  array.each { |k,v| h[k] = v }
  h
end

.to_mash(array) ⇒ Mash

Transforms an Array of key/value pairs into a Mash.

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

Parameters:

  • array (Array)

    The array of key/value pairs to transform.

Returns:

  • (Mash)

    A Mash where each entry in the Array is turned into a key/value.



35
36
37
38
39
# File 'lib/dm-core/support/ext/array.rb', line 35

def self.to_mash(array)
  m = Mash.new
  array.each { |k,v| m[k] = v }
  m
end