lundi 14 mars 2016

In my Ruby parent class, How to make 'self' reference to the correct subclass in a class method

I have a parent class with a class method create, and it create a object,

class RedisObjectBase
  def self.create(attributes)
    new_object = self.new
  end
end

The subclass inherited the parent class

class SiteCertification < ::RedisObjectBase
end

class StaffCertification < ::RedisObjectBase
end

But when I call SiteCertification.create then StaffCertification.create, the 'self.new' is not working as the self will reference to the wrong subclass after its been called twice

Aucun commentaire:

Enregistrer un commentaire