On Wed, May 9, 2012 at 1:52 PM, Iñaki Baz Castillo <[email protected]> wrote:
> 2012/5/9 Quintus <[email protected]>:
>> => A
>> irb(main):009:0> klass.send(:include, M)
>> => A
>> irb(main):010:0> a = klass.new
>> => #<A:0x0000000202cfe0>
>> irb(main):011:0> a.hello
>> => "HELLO"
>>
>> Alternatively, if you don’t want to pollute the given class, use #extend
>> on the instances (which is also more clean as it doesn’t require #send).
>
> Great!
>
> I've tested that first option is much faster (more than 10 times
> faster) than extending each instance, so I'll go with first solution.

Maybe also add an additional test:

irb(main):001:0> class A;end
=> nil
irb(main):002:0> module M; def hello; "hello" end end
=> nil
irb(main):003:0> M===A || A.send(:include, M)
=> A
irb(main):004:0> A.new.hello
=> "hello"

Cheers

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to