Call constructor from parent class : super « Class « Ruby






Call constructor from parent class


class Button
  def initialize(label)
  end
end
class StartButton < Button
  def initialize
    super("Start")       # invoke Button's initialize
  end
  def button_pressed
    # do start actions...
  end
end

start_button = StartButton.new

 








Related examples in the same category

1.To pass the color to the constructor of the base class, you use the special super method