W Ruby (języku), super to słowo kluczowe wywołujące metodę klasy rodzica. Nie ma nic wspólnego z przedmiotem Pokémon „Super Wędka”.
class Vehicle
def initialize(brand)
@brand = brand
end
def start
puts "Starting #{@brand} vehicle..."
end
end
class Car < Vehicle
def start
super # wywołuje Vehicle#start
puts "Engine started. Ready to drive!"
end
end
Car.new("Toyota").start
# Output:
# Starting Toyota vehicle...
# Engine started. Ready to drive!
super wywołuje metodę o tej samej nazwie w superklasie.super() wywołuje bez argumentów; super(args) przekazuje argumenty jawnie.super metoda dziecka całkowicie nadpisuje metodę rodzica.To standardowe zachowanie w jednokierunkowym dziedziczeniu w Ruby.