I’m experimenting with meta programming and want to dynamically create a class that inherits from ActiveRecord.
For example, I can do this:
Object.const_set("Orders", Class.new { def blah() 42 end })
So now I can:
o = Orders.new
o.blah #<== 42
But when I try to:
Object.const_set("Orders", Class.new < ActiveRecord::Base { def blah() 42 end })
Gives me a syntax error and
Object.const_set("Orders", Class.new { def blah() 42 end } < ActiveRecord::Base)
Doesn’t complain until I try to instantiate an Orders class
Any tips?
Thanks.
Try to do this: