From: "Kent S." Date: 2004-05-21T01:19:06+09:00 Subject: Re: Include into class after instance is created How about this: $ irb irb(main):001:0> module M1 irb(main):002:1> Const = 1 irb(main):003:1> end => 1 irb(main):004:0> module M2 irb(main):005:1> Const = 2 irb(main):006:1> end => 2 irb(main):007:0> class A irb(main):008:1> def initialize(mod) irb(main):009:2> self.class.class_eval{ include mod } irb(main):010:2> end irb(main):011:1> irb(main):012:1* irb(main):013:1* def const irb(main):014:2> puts Const irb(main):015:2> end irb(main):016:1> end => nil irb(main):017:0> A.new(M1).const 1 => nil irb(main):018:0> A.new(M2).const 2 => nil irb(main):019:0> Cheers, Kent. On May 20, 2004, at 10:33 AM, Brian Schroeder wrote: > > On Thu, 20 May 2004 23:05:10 +0900, Kent S. wrote: > >> Use Object#extend instead of include. > > Thanks for the tip. > > I need the constants defined in the module to be included in my class, > it > seems that extend only includes the instance methods. > > $ ri extend > ---------------------------------------------------------- > Object#extend > obj.extend(module, ...) => obj > ----------------------------------------------------------------------- > - > Adds to _obj_ the instance methods from each module given as a > parameter. > > Any thoughts about this? > > Regards, > > Brian > > -- > Brian Schr�der > http://www.brian-schroeder.de/ >