ruby-uebungen/Assignment_009/solution/readme.md

33 lines
429 B
Markdown
Raw Normal View History

2023-05-25 17:47:19 +02:00
# Lösung: Klasse deklarieren
2023-05-23 09:19:31 +02:00
2023-05-25 17:49:42 +02:00
```ruby
2023-05-25 17:47:19 +02:00
class Ticket
2023-05-23 09:19:31 +02:00
2023-05-25 17:47:19 +02:00
attr_reader :spiel
2024-06-24 12:50:16 +02:00
@@seriennummer = 0
2023-05-25 17:47:19 +02:00
def initialize(spiel)
2024-06-24 12:50:16 +02:00
@@seriennummer += 1
2023-05-25 17:47:19 +02:00
@spiel = spiel
@seriennummer = @@seriennummer
2023-05-23 09:19:31 +02:00
end
def to_s
2023-05-25 17:47:19 +02:00
"#{@spiel} [#{@seriennummer}]"
end
def self.verkauft
@@seriennummer
2023-05-23 09:19:31 +02:00
end
end
2023-05-25 17:47:19 +02:00
t1 = Ticket.new('Dortmund-Schalke')
t2 = Ticket.new('Hoffenheim-Stuttgart')
puts t1
puts t2
puts Ticket::verkauft
2024-06-24 12:50:16 +02:00
```