From: Trans Date: 2006-11-09T06:10:09+09:00 Subject: Re: Proc as Observer ara.t.howard@noaa.gov wrote: > On Thu, 9 Nov 2006, James Edward Gray II wrote: > > > On Nov 8, 2006, at 12:55 PM, Trans wrote: > > > >> Given your approach I think I'd just go ahead and do: > >> > >> class Proc > >> alias :update :call > >> end > > > > I thought Tim's solution was far more elegant. Notice how he resisted > > gratuitous hacking of the core. > > not to mention tim's solution can be neatly extended to > > def observer &b > o = lambda &b > class << o > alias_method 'update', 'call' > end > o > end > > in fact, you'd thing add_observer would accept a block and do exactly this. > > regards. > > -a I think that's over zealous about avoidance of core extension. This is an excellent example of when a core extension is useful. Use of a module and/or singleton here adds an additional layer of class hierarchy that is simply unnecessary. There's nothing wrong with adding #update to Proc in this case. I'm not sure why this general perception of core extension as "hack" has gained so much footing. It's really unfortunate since open classes are one the most unique and powerful features of Ruby. T.