I have a situation where I need to dynamically execute an object from a
String name. I read in pickaxe that as long as a capitalize the class
name in the string, Ruby will see it as a Constant and thusly allow me
to use it.
puts “Something done.”
cls = “Test::MyClass”
obj = cls.new
When I execute the above caller code, I get an error saying
undefined method `new’ for “Test::MyClass”:String (NoMethodError)
So, obviously, Ruby is telling me that there is no new method for the
String “Test::MyClass”. I’m trying to instantiate the class this way as
I have specific methods that return object besides String, so I’m
guessing eval(cls) isn’t appropriate for me. Also, I checked the
archives on the list with no luck.