Your suspicion is correct.
The code:
attr_accessor :guess
is equivalent to:
def guess
@guess
end
def guess=(new_value)
@guess = new_value
end
That is, it creates a method which fetches the value of the instance variable and another method which sets the value of the instance variable.
When you redefine the method guess
later, it overwrites the method defined implicitly by attr_accessor
:
def guess
3
end
def guess
4
end
guess
#=> 4