2023-05-25 17:47:19 +02:00
|
|
|
# Lösung: Klasse dynamisch erzeugen
|
2023-05-23 09:19:31 +02:00
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
<div style="border: 1px solid grey;"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></div>```ruby
|
|
|
|
def create_class(super_class)
|
|
|
|
Class.new(super_class) do
|
|
|
|
def who_am_i
|
|
|
|
puts "Ich bin ein Kind von #{self.class.superclass}"
|
|
|
|
end
|
|
|
|
end
|
2023-05-23 09:19:31 +02:00
|
|
|
end
|
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
Test = create_class(Object)
|
|
|
|
t = Test.new
|
|
|
|
t.who_am_i
|
2023-05-23 09:19:31 +02:00
|
|
|
```
|