How to use Super in Inheritance and Classes


#1

Hi guys i have a question. i understand that "super" its used when you want to use the same attributes as the Parent class... but in this code why does it matter to put Super ?

class Message
    @@messages_sent = 0
    def initialize(from, to)
        @from = from
        @to = to
        @@messages_sent += 1
    end
end

my_message = Message.new("Phokgedi", "Pabalelo") #our instance

class Email < Message
    def initialize(from, to)
        super
    end
end

I would have just wrote:
class Email < Message; end

and this was going to inherit everything from superclass from my understanding without writing a method inside the inheritance. help me understand this concept of inheritance better if i'm wrong?


#2

https://www.codecademy.com/en/courses/ruby-beginner-en-MFiQ6/3/5


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.