From: dblack@... Date: 2003-07-21T19:18:50+09:00 Subject: Re: Proposal: Array#to_h, to simplify hash generation Hi -- On Mon, 21 Jul 2003, Gavin Sinclair wrote: > I like "make_hash". We would get more flexibility if "make_hash" insisted > on receiving two values for the block: one for key and one for value. In > one instance recently, I wanted to map the "filename" part of a data > object to the object itself. This, I think, is readable: > map = receipts.make_hash { |r| r.filename, r } > > Whereas in my pet case of mapping filename to size, we have > > map = filenames.make_hash { |fn| fn, File.stat(fn).size } > > And your example comes out as > > (1..10).make_hash { |i| i, f(i) } (Wouldn't you have to wrap your two return values in an array to get the above to parse?) > I've raised an RCR for this (#148). I'm not sure how this differs from (rejected) RCR#12 (except for having to return a key as well as a value). David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav