Let's consider the following example:
class Car < ActiveRecord::Base
def engine
@engine ||= Engine.new(self)
end
end
class Engine
def initialize(vehicle)
@vehicle = vehicle
end
def model
@vehicle.model
end
end
and what I don't understand is that when I go to the console and do something like that:
car = Car.last
car.engine.model # => 'V8'
and then
car.model = 'V6'
I get
car.engine.model # => 'V6'
It's obviously a simplified example but anyway, can anyone explain why I get a different engine model name in the last line of code? Isn't it supposed to use the @engine variable and return the previous engine model name?