From: Joel VanderWerf Date: 2006-10-29T08:01:15+09:00 Subject: Re: hash.collect Joe Ruby MUDCRAP-CE wrote: > collect seems to work on a hash: > > h = {'a'=>'1', 'b'=>'2'} > > params = h.collect {|k, v| "#{k}=#{v}"}.join('&') > > Yet collect isn't listed as a method of hash: > http://www.ruby-doc.org/core > > Is it undocumented, or is some magic going on behind the scenes -- such > as the hash getting converted to an array? The Hash class includes the Enumerable module, which defines #collect in terms of #each. In this case, Hash#each yields key,value pairs, so #collect does too. It doesn't get converted to an array before map is called. It does get converted to an array through the normal behavior of #map: irb(main):003:0> h={1=>2, 3=>4} => {1=>2, 3=>4} irb(main):004:0> h.map => [[1, 2], [3, 4]] -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407