I need to do something like that
class Foo
define perform()
puts 'hello'
end
end
classname = 'Foo'
instance = create_instance(classname)
instance.perform();
Is something like that possible. If is the how?
Thanks a lot!
You can use Module#const_get
klass = Object.const_get(classname)
instance = klass.new
But you might want to whitelist classname first if it's coming from user input. Otherwise you're potentially opening a security hole.