Ruby’s super


class Person
  def initialize(name)
    @name = name
  end

  def name
    return @name
  end
end

class Doctor < Person
  def name
    “Dr. “ + super
  end
end

That, in short, is how super works. Taken from Beginning Ruby by Peter Cooper.

super

in short calls up the parent class’ instance method.

Advertisement

About AJ

In the future, he hopes that this blogsite will be humorous, informative, and enjoyable for the visitors.
This entry was posted in Uncategorized. Bookmark the permalink.