The question is as of the title. Say I have a simple example below:
class Vehicle
attr_accessor :wheels
end
class Car < Vehicle
def initialize
self.wheels = 4
end
end
class Truck < Vehicle
def initialize
@wheels = 16
end
end
I am curious which way is considered correct or better to invoke
wheels writer method of mother Vehicle?
self.wheels = 4is more flexible because under the hood it is calling a setter method:self.wheels=(4)So if you ever wanted to do something with the value before it is placed into
@wheels, you could define that function: