From: dblack@... Date: 2003-08-12T22:28:10+09:00 Subject: Re: newbie mixin questions Hi -- On Tue, 12 Aug 2003, Robert Klemme wrote: > > "Michael Garriss" schrieb im Newsbeitrag > news:3F37F45B.8080002@earthlink.net... > > dblack@superlink.net wrote: > > > > >One other technique that might be relevant is Module#included, which > > >as I understand it is essentially a new name for append_features. (Is > > >that accurate?) Here's a 1.8.0 example: > > > > > > module M > > > def self.included(c) > > > def c.something > > > puts "I'm a class method!" > > > end > > > super > > > end > > > > > > def another > > > puts "I'm an instance method!" > > > end > > > end > > > > > >The inclusion now operates, with fairly clear separation, on both the > > >class and the instances: > > > > > > class A; include M; end > > > > > > A.something > > > A.new.another > > > > > > > > >David > > > > > > > > > > > > > That's what I needed. Thanks! > > But: you now have multiple something methods with the same definition. > That's ugly. I'd prefer the approach to extend a class with M as shown in > the other postings: I'm not sure what you mean; I only see one #something method. In any case, ugly or not, I think it's worth knowing about Module#include if one is interested in this question of class vs. instance method definition in included modules -- especially because the techniques in question are actually somewhat different from each other, in their effects (i.e., one isn't just a wordier drop-in replacement for the other). With the override of Module#included, every class that includes this module gets the new method. So if one wants to break it out with more granularity, one probably doesn't want to do it this way at all. David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav