Workaround “flip-flop deprecated” warning in Ruby

2019-07-09 11:37发布

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.

标签: ruby shell
0条回答
登录 后发表回答