Arts >> Magic >> Magic Tricks

Using `super` in Ruby Inheritance: Calling the Parent Method

In Ruby (the language), super is a keyword that calls a parent class’s method. It has nothing to do with the Pokémon item "Super Rod."

How `super` Works

class Vehicle
  def initialize(brand)
    @brand = brand
  end

  def start
    puts "Starting #{@brand} vehicle..."
  end
end

class Car < Vehicle
  def start
    super # calls Vehicle#start
    puts "Engine started. Ready to drive!"
  end
end

Car.new("Toyota").start
# Output:
# Starting Toyota vehicle...
# Engine started. Ready to drive!

Key Points

This is standard single-inheritance behavior in Ruby.

Magic Tricks

Related Categories