Sha256: 3c4126647a354bd47ad5881b4a6652187ec7bac688483b3cb0fe5749bc417de5

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module DataMapper; module Ext
  module Array
    # Transforms an Array of key/value pairs into a Hash.
    #
    # This is a better idiom than using Hash[*array.flatten] in Ruby 1.8.6
    # because it is not possible to limit the flattening to a single
    # level.
    #
    # @param [Array] array
    #   The array of key/value pairs to transform.
    #
    # @return [Hash]
    #   A Hash where each entry in the Array is turned into a key/value.
    #
    # @api semipublic
    def self.to_hash(array)
      h = {}
      array.each { |k,v| h[k] = v }
      h
    end

    # Transforms an Array of key/value pairs into a {Mash}.
    #
    # This is a better idiom than using Mash[*array.flatten] in Ruby 1.8.6
    # because it is not possible to limit the flattening to a single
    # level.
    #
    # @param [Array] array
    #   The array of key/value pairs to transform.
    #
    # @return [Mash]
    #   A {Mash} where each entry in the Array is turned into a key/value.
    #
    # @api semipublic
    def self.to_mash(array)
      m = Mash.new
      array.each { |k,v| m[k] = v }
      m
    end
  end # class Array
end; end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dm-core-1.1.0 lib/dm-core/support/ext/array.rb
dm-core-1.1.0.rc3 lib/dm-core/ext/array.rb