Skip to main content
4 of 5
deleted 38 characters in body; edited title
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Switching state of a class variable in Ruby (between two options)

Is there a better way to do this? That switch_status method seems like it could be made a lot more compact.

class Taxi
  def initialize
    @status = :available
  end  

  def switch_status
    if @status == :available
      @status = :busy
    else
      @status = :available
    end
  end
end

t = Taxi.new
t.switch_status