------ art_65563_30923764.1168768253676 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 1/13/07, Wilson Bilkovich <wilsonb / gmail.com> wrote: > > On 1/13/07, Robert Dober <robert.dober / gmail.com> wrote: > > On 1/13/07, Martin DeMello <martindemello / gmail.com> wrote: > > > > > > On 1/13/07, Mauricio Fernandez <mfp / acm.org> wrote: > > > > > > > > Do you feel that store_{once,new,unique} is too long? > > > > (I have a slight preference for "once"; "unique" seems a bit > puzzling > > > since it > > > > seems to refer to the key, which is always unique) > > > > > > Even 'store_once' seems to refer to the value rather than the pair, > > > which is why I like "underlay" - it suggests that if there is > > > something already in the hash, it will mask the value you are trying > > > to add. > > Can we please just agree to write: > hash[key] alue unless hash.key?(key) > I mean.. how often do you do this? I think it is clear that I would like to have this feature so sorry for replying anyway. This would be more than a convenience method it would be autodocumenting Hash even better, it would make its API clearer. Somebody was saying in this thread, why do you not write hash[key] || alue you and I know better of course but if one has to read code to see hash[key] alue unless hash.key? key one could think poor guy he does not even know about the "hash[key] ||value" idiom. OTH if in rdoc one saw Hash#insert_once(key, value) sets value only if key is not in the hash already, pleas note that this is not the same as hash[key] || alue as... one would probably believe, no? Cheers Robert -- "The best way to predict the future is to invent it." - Alan Kay ------ art_65563_30923764.1168768253676--