拨动开关 / T-Flip 翻转

Toggle switch / T-Flip Flip

我在尝试将触发器应用于以下场景时遇到问题。假设我有以下数组:

[ 'on',
  'random text',
  'random text',
  'random text',
  'random text',
  'off'
  'random text',
  'random text',
  'on'
  'random text',
  'off'
  'random text',
  'random text',
   etc...

我想要一个开关根据两个值之一翻转(如数组中的 'on' 和 'off' 所示)

感谢任何帮助

你的数据是一个简单的触发器示例。

x = [ 'on',
  'random text',
  'random text',
  'random text',
  'random text',
  'off',
  'random text',
  'random text',
  'on',
  'random text',
  'off',
  'random text',
  'random text'
]

x.each do |text|
  if text['on'] .. text['off']
    puts text
  end
end

#on
#random text
#random text
#random text
#random text
#off
#on
#random text
#off