Sha256: 3c27502de09e388e430c512786fc0640af467311506875675eedcfba838f99b2
Contents?: true
Size: 627 Bytes
Versions: 26
Compression:
Stored size: 627 Bytes
Contents
class Hash # Creates a new hash from two arrays --a keys array and # a values array. # # Hash.zipnew(["a","b","c"], [1,2,3]) # #=> { "a"=>1, "b"=>2, "c"=>3 } # def self.zipnew(keys,values) # or some better name h = {} keys.size.times{ |i| h[ keys[i] ] = values[i] } h end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TC01 < Test::Unit::TestCase def test_zipnew a = [1,2,3] b = [4,5,6] assert_equal( {1=>4,2=>5,3=>6}, Hash.zipnew(a,b) ) end end =end
Version data entries
26 entries across 26 versions & 1 rubygems