In ruby, is there any method for changing the value of a variable between two values based on its current value?
I need something like this:
var = 'value one'
var.flip('value one', 'value two')
puts var # => 'value two'
I think that you can use the ruby ternary operator or the if - else contruction like this
var1 = 2 var1 = 3 == var1 ? var1 : 2
irb(main):049:0> var1 = if 4 == var1 then var1 else 2 end => 4 i