From: ts Date: 2001-11-02T19:15:39+09:00 Subject: [ruby-talk:24156] Re: Dynamic object type from variable >>>>> "M" == Matthew Diephouse writes: M> class A M> ... M> method=(class) M> @var = class.new(self) M> end M> end Well, you can do it with eval, but you can also make weird thing with eval. When ruby create a class, it create a constant with the same name just retrieve this constant. For example pigeon% cat b.rb #!/usr/bin/ruby class A attr_reader :var def cmethod=(klass) cl = Object klass.split('::').each {|l| cl = cl.const_get l } @var = cl.new end end module B class C end end class D end a = A.new a.cmethod = "B::C" p a.var a.cmethod = "D" p a.var pigeon% pigeon% b.rb # # pigeon% Guy Decoux