From: Sam Roberts Date: 2008-05-07T14:20:00+09:00 Subject: Re: delegation question, where I want prototype style delegation On Tue, May 6, 2008 at 5:58 AM, James Gray wrote: > On May 6, 2008, at 1:00 AM, Sam Roberts wrote: > > > > I want to make an object that behaves like another object would, if that > > object had had it's #each method redefined. > > > > What you really want in this case is normal inheritance, so the overridden > each() method replaces the original. Educational code, but doesn't quite do the trick, because the views aren't stackable. In my example I negated, added 10, and negated again. With yours: puts "Stacked operations:" puts b.as_negated.as_plus_10.as_negated.show => in `method_missing': undefined method `as_plus_10' for # (NoMethodError) The end result of this would have to be an instance of class Negated < Plus10 < Negated < Base end or something... Also, my real class has much more complex internal state and relationships, it isn't just a wrapper for an Array, and creating a new instance isn't desireable. I'm trying to create calendar views, where the view of the calendar looks like the real calendar (including reflecting changes in the base calendar), but iterates over only dates in a particular range, or only journal entries. Thanks, Sam