Ruby String to Class Name

后端 未结 7 894
感情败类
感情败类 2020-12-24 12:32

I am trying to create a new class to that will inherit from ActiveRecord::Base the class needs to be dynamically generated from a string

\"gener         


        
相关标签:
7条回答
  • 2020-12-24 13:29

    Something like this?

    >> Object.const_set("general_systems".classify, Class.new)
    => GeneralSystem
    >> GeneralSystem.new
    => #<GeneralSystem:0x105b0f738>
    
    0 讨论(0)
提交回复
热议问题