← Back to Ruby Operators

Flip Flop

The flip flop operator (flipfloperator) is a special form of conditional syntax. The syntax looks like the range feature.

When the left side of the flip flop is true, then the condition evaluates to true. Once the left side of the condition becomes true then it evaluates to false.

Here is an example from the Ruby docs:

> selected = []
=> []

0.upto 10 do |value|
  selected << value if value==2..value==8
end
=> 0

> selected
=> [2, 3, 4, 5, 6, 7, 8]

Once the value is 2, the left side of the flip flop is true and values are shoveled into the array. Iteration continues and when the value is 8, the left side of the flip flop becomes true making the condition evaluate to false. No more values are shoveled into the array.

There is also an exclusive range version that uses ....

References