From: Robert Klemme Date: 2012-05-09T22:34:51+09:00 Subject: Re: How to make a given klass to include a module On Wed, May 9, 2012 at 1:52 PM, Iñaki Baz Castillo wrote: > 2012/5/9 Quintus : >> => A >> irb(main):009:0> klass.send(:include, M) >> => A >> irb(main):010:0> a = klass.new >> => # >> 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/