2023-05-25 17:47:19 +02:00
|
|
|
# Lösung: Metaprogrammierung: Die kleine Petze
|
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 Snitch
|
|
|
|
def method_missing(name, *args, **keywords, &block)
|
|
|
|
puts "Aufruf von Methode '#{name}'"
|
|
|
|
puts " mit den Argumenten #{args}"
|
|
|
|
puts " mit den Argumenten #{keywords}"
|
|
|
|
puts " und dem Block #{block}"
|
|
|
|
end
|
2023-05-23 09:19:31 +02:00
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
def to_s
|
|
|
|
puts "Aufruf von Methode 'to_s'"
|
2023-05-23 09:19:31 +02:00
|
|
|
end
|
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
# Weiter Methoden von Object überschreiben. Hier weggelassen.
|
2023-05-23 09:19:31 +02:00
|
|
|
end
|
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
snitch = Snitch.new
|
|
|
|
puts snitch
|
|
|
|
```
|