From: "ara.t.howard" Date: 2007-08-01T02:48:32+09:00 Subject: Re: redefining methods On Jul 31, 2007, at 11:27 AM, dohzya wrote: > Le mardi 31 juillet 2007 � 23:48 +0900, ara.t.howard a �crit : >> i was playing with this last night, thought some here might be >> interested: >> >> http://drawohara.tumblr.com/post/7241442 >> >> cheers. >> >> a @ http://drawohara.com/ >> -- >> we can deny everything, except that we have the possibility of being >> better. simply reflect on that. >> h.h. the 14th dalai lama > > Just for the syntax, I don't like : > --- > redefining :foo do > def foo(*a, &b) super.reverse end > end > --- > I prefer : > --- > redefining :foo do |*a, &b| > super.reverse > end > --- > Greater, it isn't ? absolutely. and when define_method takes a block that would indeed by the way to do it. > --- > > However, there is an other way : > --- > redefining :foo do |&old| # &old or old, see after > def foo(*a, &b) old.call.reverse end > end > --- this can't work though - old is not in scope inside foo - only with define_method would that be possible, but there you lose the ability to define methods which themselves take blocks... > and maybe... > --- > redefining :foo do |*olds| # list, ordered (asc or desc ?) > def foo(*a, &b) (olds.shift.call + olds.shift.call).reverse end > # maybe add a shortcut for shift.call... > end > --- again - same issue with scoping. although i agree and more closure based solution would be nice. for now though - i don't think it's possible. i'd be very happy to be proven wrong though! ;-) kind regards. a @ http://drawohara.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama