Hello
I need to find a classe when I have its name in a string like this
module Tutu
class Toto
end
end
module Popo
class Pupu
def truc
toto_class=FIND(‘Tutu::Toto’)
toto=toto_class.new
end
end
end
Someone have an idea ?
Bye
Hello
I need to find a classe when I have its name in a string like this
module Tutu
class Toto
end
end
module Popo
class Pupu
def truc
toto_class=FIND(‘Tutu::Toto’)
toto=toto_class.new
end
end
end
Someone have an idea ?
Bye
your FIND is Module#const_get
irb(main):001:0> Object::const_get ‘Class’
=> Class
irb(main):002:0> class Mia; end
=> nil
irb(main):003:0> Object::const_get(‘Mia’).new
=> #Mia:0x27cb920
il Thu, 18 Mar 2004 11:22:00 +0100, “guillaume.dorchies” guillaume.dorchies@wanadoo.fr ha scritto::
Hello
I need to find a classe when I have its name in a string like this
Ok thank but with old messages I make this method
module Introspection
class ClassNotFound < Exception ; end
class Find
def self.find_class(class_name)
ObjectSpace.each_object(Module) do |n|
if n.name==class_name then
return n
end
end
raise ClassNotFound
end
end
end
Le Thu, 18 Mar 2004 10:33:51 +0000, gabriele renzi a écrit :
il Thu, 18 Mar 2004 11:22:00 +0100, “guillaume.dorchies” > guillaume.dorchies@wanadoo.fr ha scritto::
Hello
I need to find a classe when I have its name in a string like this
your FIND is Module#const_get
irb(main):001:0> Object::const_get ‘Class’
=> Class
irb(main):002:0> class Mia; end
=> nil
irb(main):003:0> Object::const_get(‘Mia’).new
=> #Mia:0x27cb920