ruby-uebungen/Assignment_011/solution
Thomas Smits 58bc23516c Update of exercises 2023-05-25 17:49:42 +02:00
..
readme.md Update of exercises 2023-05-25 17:49:42 +02:00

readme.md

Lösung: Vererbung

class Mensch
  attr_reader :name, :alte

  def initialize(name, alter)
    @name, @alter = name, Integer(alter)
  end

  def to_s
    "#{@name}, Alter: #{@alter}"
  end
end

class Student < Mensch
  attr_reader :matrikel_nr

  def initialize(name, alter, matrikel_nr)
    super(name, alter)
    @matrikel_nr = matrikel_nr
  end

  def to_s
    super + ", Matrikel-Nr.: #{@matrikel_nr}"
  end
end

s = Student.new('Emil Meier', 22, '1822233')