ruby-uebungen/Assignment_009/solution/readme.md

25 lines
476 B
Markdown
Raw Normal View History

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