VALID_STATES = %i[open closed invalid wontfix]
def status= new_state
new_state = new_state.to_sym
@status = new_state
t = Ticket.new
t.status = 'closed'
@status = :closed
@status = new_state.to_sym
def foo=(str); @foo = str.to_sym; end
It's expected. From the documentation:
Note that for assignment methods the return value will always be ignored. Instead, the argument will be returned:
def a=(value) return 1 + value end p(a = 5) # prints 5
Ruby allows you to chain assignments:
foo = bar = 'closed'
The above assigns
"closed" to both,
Returning the argument and ignoring the method's return value lets you replace
bar with a method call:
foo = t.status = 'closed'
IMO it would be quite surprising if the above would assign
If you really want the return value, use
def a=(value) return 1 + value end p(a = 5) # prints 5 p(send(:a=, 5)) # prints 6