From: "David A. Black" Date: 2005-04-23T20:40:53+09:00 Subject: Re: Suggestion: Hash.remove Hi -- On Sat, 23 Apr 2005, Lyndon Samson wrote: > On 4/23/05, Andrew Walrond wrote: >> Something I often find useful is a version of Hash.delete which returns the >> hash rather than the deleted item. Useful for terse chained code. >> >> class Hash >> def remove!(*some_keys) >> some_keys.each { |key| delete(key) } >> return self >> end >> def remove(*some_keys) >> return dup.remove!(*some_keys) >> end >> end >> >> Perhaps something like it is already planned for the next version? If not, >> perhaps the Hash maintainer might consider something like it. >> > > I think there is a bias against method chaining by the Ruby Powers-that-Be. I don't think so -- just a design decision in the case of bang methods (they don't generally return self when there's no change, so they can't be chained). It's a little tricky with hashes, because the standard currency, so to speak, of a lot of Enumerable methods is the array. So if you do, for example, find, select, reject, map, etc. on a hash, you get back an array. David -- David A. Black dblack@wobblini.net