class Dog
attr_reader :age, :dog_years
def dog_years=(years) # write
@dog_years = years
end
def age=(years) # write
@age = years
self.dog_years = years * 7
end
private :dog_years=
end
rover = Dog.new
rover.age = 10
# calling private method
# bcz dog_years method is private
# we can not call it directly
# so we call self.dog_years
# that is in the age= method
puts rover.dog_years
we can not amounting private method directly
this is wrong way
puts rover.dog_years=(70)
Top comments (0)