From: Robert Klemme Date: 2005-06-07T23:40:26+09:00 Subject: Re: making a duck Eric Mahurin wrote: > --- nobu.nokada@softhome.net wrote: >> At Tue, 7 Jun 2005 11:59:47 +0900, >> Eric Mahurin wrote in [ruby-talk:144750]: >>> Is there an advantage to having a separate Behavior class >> as >>> opposed the solution I had: making a singleton Object >> directly? >> >> To allow sharing same behavior. > > I'm not sure how much application this would have over the > conventional class definition approach. > > At first I didn't think this would work because I thought you > wouldn't be able to create any instance variables using > define_method. I thought any @ variables in a proc would refer > to the @ variable in the original context, but define_method > apparently rebinds them to the object. I always remind myself that the binding of "self" changes - even for each method invocation. This explains pretty good why this works as it should. 16:31:18 [ruby]: ruby x.rb 4 666 666 16:38:10 [ruby]: cat x.rb o=Object.new def o.size() 666 end x="test" class<