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