is there way to convert object into another class in ruby -
let have model
user < activerecord::base end and sti brother
masqueradeuser < user end masquerade_user = masqueradeuser.find 123 masquerade_user.class # => masqueradeuser ridiculous sounds, possible convert object parent class user
masquerade_user.some_magic.class # => user i know can override methods mode_name, is_a?(user) , other masqueradeuser return values user
masqueradeuser < user def model_name 'user' end end i wondering if there way downgrade object parent class instance
you can use becomes function of activerecord - see here.
Comments
Post a Comment