Skip to main content
edited title
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

Switching state of Toggling a class variable in Ruby (between two options)taxi between busy and available states

deleted 38 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

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

Is there a better way to do this? That switch_statusswitch_status method seems like it could be made a lot more compact. Any advice would be most appreciated :)

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

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. Any advice would be most appreciated :)

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

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
Post Reopened by TheCoffeeCup, mdfst13, Alex L, tokland, Flambino
added 2 characters in body
Source Link

Is there a better way to do this? That switch_status method seems like it could be made a lot more compact. Any advice would be most appreciated :)

class FooTaxi
  def initialize
    @status = :available
  end  

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

ft = FooTaxi.new
ft.switch_status

Is there a better way to do this? That switch_status method seems like it could be made a lot more compact. Any advice would be most appreciated :)

class Foo
  def initialize
    @status = :available
  end  

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

f = Foo.new
f.switch_status

Is there a better way to do this? That switch_status method seems like it could be made a lot more compact. Any advice would be most appreciated :)

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
Post Closed as "Not suitable for this site" by 200_success
added 40 characters in body
Source Link
Loading
Source Link
Loading