From: Matthew Smillie Date: 2006-06-20T06:59:19+09:00 Subject: Re: associative array naming indirection > Related: The reason for futzing with .upto() was to deal with a > variable > length of input array needing to access labels in a given order. Is > there a better way? That depends. If having 'nil' values in your hash is OK, you could still use #zip labels = ['a', 'b', 'c', 'd', 'e', 'f'] data = [1, 2, 3] Hash[*labels.zip(data).flatten] => {"a"=>1, "b"=>2, "c"=>3, "d"=>nil, "e"=>nil, "f"=>nil} or #inject, if you're feeling slightly obscurantist. labels.inject({}) { |hsh, label| hsh.merge({label => data.shift}) } => {"a"=>1, "b"=>2, "c"=>3, "d"=>nil, "e"=>nil, "f"=>nil} Or one of the other iteration methods in Array and Enumerable. data.each_index { |idx| hsh[labels[idx]] = data[idx] } data.each_with_index { |datum, idx| hsh[labels[idx] = datum } hsh => {"a"=>1, "b"=>2, "c"=>3} Browse through the docs, they're the most help in situations like this. matthew smillie.