Class: Array
Direct Known Subclasses
Instance Method Summary collapse
-
#to_hash ⇒ Hash
Transforms an Array of key/value pairs into a Hash.
-
#to_mash ⇒ Mash
Transforms an Array of key/value pairs into a Mash.
Instance Method Details
#to_hash ⇒ 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.
14 15 16 17 18 |
# File 'lib/dm-core/core_ext/array.rb', line 14 def to_hash h = {} each { |k,v| h[k] = v } h end |
#to_mash ⇒ 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.
31 32 33 34 35 |
# File 'lib/dm-core/core_ext/array.rb', line 31 def to_mash m = Mash.new each { |k,v| m[k] = v } m end |