Inheritance and super
< inherits. super calls the parent method.
Example
class Animal
def speak = "..."
end
class Cat < Animal
def speak = super + " meow"
end
puts Cat.new.speak, Cat.superclass, Cat.ancestors.first(2).inspectResult
... meow Animal [Cat, Animal]
Exercise
Inherit.
class Cat Animal
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.