From: Gavin Kistner Date: 2005-05-17T21:41:25+09:00 Subject: Re: Extending an Instance only Once --Apple-Mail-1-587503984 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On May 17, 2005, at 5:34 AM, David A. Black wrote: > Unless I'm missing something, #is_a? would do it. Nope, apparently it was I who missed something. Thanks :) > The singleton class takes precedence in the sense that it comes > earlier in the method lookup path. (I'm assuming that you mean mixing > the module into the class, not MyClass.extend(MyMod), which would not > affect the class's instances.) Indeed, that is what I meant. module M; end class Foo; end class Bar; include M; end f = Foo.new b = Bar.new f.is_a?( M ) #=> true b.is_a?( M ) #=> true Yay :) > Overall, I'm tempted to say that if you're extending a single object > multiple times with the same module, there's something not quite right > in the program flow. But I doubt it's going to slow things down very > much (but I haven't benchmarked it). Yeah, I could certainly realize _some_ performance gain by ensuring that the consumer of the class ensures that they pre-mix any instances which are handed to the method. But I'm going for uber- friendliness, sort of auto-duck-typing. ("You say you don't quack like a duck? Here, let me strap this bill onto your head.") When I get to benchmarking I'll check it out, but I think it should be fine, since this method is run only a few times during setup, and not during the cpu-intensive phase. --Apple-Mail-1-587503984--