2023-05-25 17:47:19 +02:00
|
|
|
# Lösung: Zugriffsmethoden
|
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></div>
|
2023-05-23 09:19:31 +02:00
|
|
|
```ruby
|
2023-05-25 17:47:19 +02:00
|
|
|
class Professor
|
|
|
|
attr_reader :name
|
|
|
|
attr_accessor :fach
|
2023-05-23 09:19:31 +02:00
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
def initialize(name, fach)
|
|
|
|
@name = name
|
|
|
|
@fach = fach
|
|
|
|
end
|
2023-05-23 09:19:31 +02:00
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
def to_s
|
|
|
|
"Prof. #{@name} lehrt #{fach}"
|
|
|
|
end
|
2023-05-23 09:19:31 +02:00
|
|
|
end
|
|
|
|
|
2023-05-25 17:47:19 +02:00
|
|
|
p = Professor.new('Smits', 'PR3')
|
|
|
|
puts p.name
|
|
|
|
puts p.fach
|
|
|
|
p.fach = 'WIA'
|
|
|
|
puts p.fach
|
2023-05-23 09:19:31 +02:00
|
|
|
```
|