$class = "MyClass";
$instance = new $class;
actually this is bad practice, in Ruby arata asa:
class MyClass; end
some_outside_class = 'MyClass' # use a white-list in real life or better yet just avoid it
klass =
begin
Module.const_get(some_outside_class)
rescue NameError
puts "The #{some_outside_class} class does not exist"
end
exit unless klass
instance = klass.new
instance.object_id
# => 70131611385580
Less magic, fully explicit ironic cum some people se plang ca Ruby este full of magic