I came to ruby from PHP. How could i do the next thing in ruby?
$className = 'ArrayObject';
$arrayObject = new $className();
Thank you for any help!
I came to ruby from PHP. How could i do the next thing in ruby?
$className = 'ArrayObject';
$arrayObject = new $className();
Thank you for any help!
You can also use the following if you are using Ruby on Rails:
array_object = "Array".constantize.new
If you have a class, like for example String:
a = String
a.new("Geo")
would give you a string. The same thing applies to other classes ( number & type of parameters will differ of course ).