From: Shannon Fang Date: 2005-10-25T17:16:22+09:00 Subject: Re: RCR: Array#to_h Hi Robert, 1) Set won't work. I am not only test if an element exist or not, I want to assign value to the key to track its status. 2) I have not write any RCR before, so I may make mistakes. I will certainly propose a good use case, when I have a complete one. 3) >Problem is, that there are other conversions that are at least equally >reasonable (e.g. the one Nobu presented). IMHO there is not a single >reasonable way to implement Array#to_h so it's better to leave it out. >Maybe it's just a naming issue though. Yes I agree it is a name issue. Thanks, Shannon >From: "Robert Klemme" >Reply-To: ruby-talk@ruby-lang.org >To: ruby-talk@ruby-lang.org (ruby-talk ML) >Subject: Re: RCR: Array#to_h >Date: Tue, 25 Oct 2005 16:32:02 +0900 > >Shannon Fang wrote: > > Hi Matz, > > > >> Rejected. Proposal Array#to_h(value=nil) does not actually solve the > >> problem above. If you want to have _this_ to_h, you need to have > >> a proper usecase. > > > > I don't know what you mean the "problem above"... My purpose is to > > have a convenient way to convert array to hash for *indexing* or > > *fast searching* purpose. > >If you just want a fast access to those elements a Set is sufficient - and >you can use #to_set already: > > >> require 'set' >=> true > >> a=%w{foo bar baz} >=> ["foo", "bar", "baz"] > >> s=a.to_set >=> # > >> s.include? "foo" >=> true > >> s.include? "fo" >=> false > > > This indeed is a bit ad-hoc, but it is useful in may cases. > >I think Matz just asked you to present these use cases. Apart from your >general description I couldn't find one in the thread. Did I miss >something? > > > I > > deliberately wanted to map array value (not index) to hash key... > > otherwise I think it is not useful (i.e., map array key => hash key). > >Problem is, that there are other conversions that are at least equally >reasonable (e.g. the one Nobu presented). IMHO there is not a single >reasonable way to implement Array#to_h so it's better to leave it out. >Maybe it's just a naming issue though. > >Kind regards > > robert > >