Get a class by name in Ruby?

后端 未结 4 1132
眼角桃花
眼角桃花 2020-12-02 14:01

Having a string with the module and name of a class, like:

\"Admin::MetaDatasController\"

how do I get the actual class?

The follow

4条回答
  •  情书的邮戳
    2020-12-02 15:02

    i could be way off-base, but wouldn't eval return the class?

    eval("Admin::MetaDatasController")
    

    so eval("Admin::MetaDatasController").new would be the same as Admin::MetaDatasController.new

提交回复
热议问题