How can this line in Java be translated to Ruby:
String className = "java.util.Vector";
...
Object o = Class.forName(className).newInstance();
Thanks!
Object::const_get('String').new()
如果您正在使用ActiveSupport(即Rails),则会向String
添加一个方法来执行此操作:
"String".constantize.new
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.