Sha256: 6787d1625dac2c5ce3b55f7fe935a4a58b3f0cc1e8ccf5f8fa66d7dc49afe996

Contents?: true

Size: 813 Bytes

Versions: 26

Compression:

Stored size: 813 Bytes

Contents

class Array

  # Converts an array into a hash.
  #
  # This methd is just like Enumerable#to_h. But has
  # been moved in order to accomodate associtiave
  # arrays. We use to_hash becasue an Array is, 
  # in essence, a hash, just with a restricted
  # set of keys and maintained order.
  #
  #   a = [ :a, :b, :c ]
  #   a.to_hash  #=> { 0=>:a, 1=>:b, 2=>:c }
  #
  #--
  # Change to alias to_h from Enumerable?
  #++
  def to_hash
    h = {}
    each_with_index{ |e,i| h[i] = e }
    h
  end
      
end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCArray < Test::Unit::TestCase

    def test_to_hash
      a = [:a,:b,:c]
      assert_equal( { 0=>:a, 1=>:b, 2=>:c }, a.to_hash )
    end

  end

=end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/array/to_hash.rb
facets-1.0.3 packages/core/lib/facet/array/to_hash.rb
facets-1.0.0 lib/facet/array/to_hash.rb
facets-1.2.1 lib/facets/core/array/to_hash.rb
facets-1.1.0 lib/facet/array/to_hash.rb
facets-1.2.0 lib/facets/core/array/to_hash.rb
facets-1.3.0 lib/facets/core/array/to_hash.rb
facets-1.3.1 lib/facets/core/array/to_hash.rb
facets-1.3.2 lib/facets/core/array/to_hash.rb
facets-1.3.3 lib/facets/core/array/to_hash.rb
facets-1.4.1 lib/facets/core/array/to_hash.rb
facets-1.4.0 lib/facets/core/array/to_hash.rb
facets-1.4.2 lib/facets/core/array/to_hash.rb
facets-1.4.3 lib/facets/core/array/to_hash.rb
facets-1.4.4 lib/facets/core/array/to_hash.rb
facets-1.4.5 lib/facets/core/array/to_hash.rb
facets-1.7.0 lib/facets/core/array/to_hash.rb
facets-1.7.38 lib/facets/core/array/to_hash.rb
facets-1.7.30 lib/facets/core/array/to_hash.rb
facets-1.7.46 lib/facets/core/array/to_hash.rb