Ruby String to Class Name

后端 未结 7 923
感情败类
感情败类 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
    => #
    

提交回复
热议问题