From: dblack@... Date: 2003-01-19T02:56:50+09:00 Subject: Re: Feature request: Array.to_h Hi -- On Sun, 19 Jan 2003, Tom Payne wrote: > dblack@candle.superlink.net wrote in message news:... > > Also, I think you're doing it backwards :-) For one > > thing, if you've got duplicate values in your array, your hash will > > end up truncated. Also, I think an indexed #to_h sort of grows out of > > the idea that an array is, or can be viewed as, a hash whose keys > > happen to be positive integers. That means that you'd want the > > indices to be the *keys* of the new hash, not the values. > > The code I posted does use the indicies as the keys: > > irb(main):014:0> h = [:a, :b, :c].to_h > => {0=>:a, 1=>:b, 2=>:c} > irb(main):015:0> h.keys > => [0, 1, 2] Whoops, sorry, I inverted your inversion. > Glad we're otherwise in agreement :-) Almost :-) See . I seem to evade naming any of the variants just "to_h" (they're to_h_raw, to_h_ikeys), etc. I'm inclined to think "to_h" would be what I called "to_h_raw", i.e.: [1,2,3,4].to_h => { 1 => 2, 3 => 4 }, but I'm not sure. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav