From: Robert Klemme Date: 2004-10-23T19:04:11+09:00 Subject: Re: #extend_object only for #extend and not #include "Gavin Kistner" schrieb im Newsbeitrag news:DB3F483A-2483-11D9-845E-000A959CF5AC@refinery.com... > On Oct 22, 2004, at 8:09 AM, Robert Klemme wrote: >> "Gavin Kistner" schrieb im Newsbeitrag >> news:8529C86C-2430-11D9-A186-000A959CF5AC@refinery.com... >>> Just thought I'd point out my surprise that the Module#extend_object >>> callback only fires when #extend is explicitly called, and not when the >>> module extends the class via #include: >> Well, that's quite logical, isn't it? I mean, include and extend are two >> different cups of tea. > > Are they? Other than different receivers (and thus the ability for #extend > to operate on instances) are they functionally different and I'm a moron > for not realizing it? Well, maybe I'm the moron. Lemmesee... I think, we're both right: include and extend are different because they have different receivers: include's receiver must be a Module (or sub class) while extend's receiver must be an instance. Behind the scenes of course, extend should do something like this - at least conceptually: def extend(x) class << self include x end end I guess the reason why we see differences here is the fact that singleton classes are handled specially and thus maybe don't invoke Module#included. >> def self.included( o ) >> p "#{o} just included #{self}" >> end > > Apparently I didn't know about this. That'll do...thanks! :) So now you have two options: either recognize include and extend differently or treat them alike. I find this pretty complete: you got the choice. :-) Btw: *I* didn't know about append_features - so we all have learned something. :-) Kind regards robert