Search code examples
rubyshell

Workaround "flip-flop deprecated" warning in Ruby


I invoke Ruby from my shell script like this:

ruby -n -e "print if %r($fromre)...%r($tore)" "$@"

Since Ruby 2.6, I get the warning

warning: flip-flop is deprecated

So it seems that i have to be prepared that the wise high priests of Ruby have decided that this (IMO useful) construct will be completely gone one day.

What would be an easy work-around? Of course I can replace

print if %r($fromre)...%r($tore)

by

inside ||= %r($fromre)
if inside
  print
  inside = false if %r($tore)
end

but I wonder whether there is a more concise way to write this.


Solution

  • In July 2019 the original author of Ruby agreed to leave flip-flops in the language:

    I hear the negative feedback from the community. OK, I give up. The warning should be removed.

    Matz.

    The warning was removed shortly thereafter and the change was backported to Ruby 2.6.