ruby动态new对象
程序员文章站
2022-03-11 09:38:58
...
来自railscn的讨论:
http://www.railscn.com/viewtopic.php?t=2289
1
.
eval
"
obj = #{str}.new
"
#
只能在irb中使用
2 . obj = eval " obj = #{str}.new "
3 . obj = eval (str) . new
4 . c = Object . const_get( " Array " )
s = c . new
2 . obj = eval " obj = #{str}.new "
3 . obj = eval (str) . new
4 . c = Object . const_get( " Array " )
s = c . new
相比于java的class.forName,与javascript等脚本语言一致,更为简单和轻量级