From: Florian Gross Date: 2006-06-06T19:20:53+09:00 Subject: Re: Array.to_hash Nitay wrote: > I like your from_assoc idea, and support the notion that it should be > added. > What was the status of it? It's not added in 1.9 yet. I'm not even sure if I posted a RCR or RFE for this. If so I didn't get much feedback. > I also think a specific one for array (or Enumerable mixin maybe?) is > useful > because it is very clear cut and understandable since it is specific to one > class. Hm, I think that checking that the passed object is indeed in the form of [[x, y], ...] would be a good idea. It would probably make sense to check both the inner and outer arrays for being direct or indirect instances of Array. As far as I understand Array#lassoc and #rassoc already have those checks. > As far as I know, there are not many ruby from_X methods, whereas > there are many to_Y ones, which I believe makes it more immediately > apparent what the method will do. That is true, but Array#assoc_to_hash seems a bit odd to me. It's definitely not Array#to_hash because it doesn't work with all arrays. I think .to_hash would work like this: ["foo", "bar"].to_hash # => { 0 => "foo", 1 => "bar" } But I don't think that such a .to_hash is necessary. I think Hash.from_assoc is more important because it is commonly needed. And most of the time it is implemented as Array[*assoc.flatten] which has problems because flatten is recursive. -- http://flgr.0x42.net/