On Wed, 27 Dec 2006, Daniel Berger wrote: > > The solution that Martin came up with is to use an UnboundMethod like > so: > > class Hash > hset = self.instance_method(:[]=) > > define_method(:[]=) do |key, value| > if self[key] > self[key] << value > else > hset.bind(self).call(key, [value]) > end > end > end here, however, you've lost any block that goes with the method ;-( > So, now our custom Hash#[]= method is bound to an UnboundMethod that no > one else has access to (see the first link below for a better > explanation). Pretty neat, eh? Is there any downside to this approach? > If not, it seems this technique ought to be filed under 'best > practices', and perhaps even abstracted somehow in the core itself. there are several problems related to scoping: http://groups-beta.google.com/group/comp.lang.ruby/browse_frm/thread/601ee261a57d7e57/09a22a5ca639834f?lnk=gst&q=harp+push_method&rnum=1#09a22a5ca639834f regards. -a -- if you find yourself slandering anybody, first imagine that your mouth is filled with excrement. it will break you of the habit quickly enough. - the dalai lama