Why is a Ruby setter method returning a String rather than a Symbol as the last expression evaluated?
问题 Unexpected Return Value from Method: Expecting Symbol I have the following Ticket class: class Ticket VALID_STATES = %i[open closed invalid wontfix] attr_reader :status def status= new_state new_state = new_state.to_sym @status = new_state end end When passed a String rather than a Symbol, the setter method unexpectedly returns a String, even though the correct value is being returned by the getter method. For example: t = Ticket.new t.status = 'closed' #=> "closed" t.status #=> :closed It