我需要做那样的事情
class Foo
define perform()
puts 'hello'
end
end
classname = 'Foo'
instance = create_instance(classname)
instance.perform();
Run Code Online (Sandbox Code Playgroud)
这样的事情是可能的.如果是这样的?
非常感谢!
你可以使用const_get:
instance = Object.const_get(classname).new
instance.perform
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3188 次 |
| 最近记录: |