Ruby 如何修正Rubocop中的风格/多重比较攻击?

Ruby 如何修正Rubocop中的风格/多重比较攻击?,ruby,rubocop,Ruby,Rubocop,当我运行rubocop时,我不断受到攻击: bin/main:70:6:C:Style/MultipleComparison:避免将变量与条件中的多个项进行比较,使用数组#include?相反 我的代码: if board1 == [1, 2, 3] || board1 == [4, 5, 6] || board1 == [7, 8, 9] || board1 == [3, 5, 7] || board1 == [1, 5, 9] || board1 == [1, 4, 7] ||

当我运行rubocop时,我不断受到攻击:

bin/main:70:6:C:Style/MultipleComparison:避免将变量与条件中的多个项进行比较,使用数组#include?相反

我的代码:

if board1 == [1, 2, 3] || board1 == [4, 5, 6] || board1 == [7, 8, 9] ||
   board1 == [3, 5, 7] || board1 == [1, 5, 9] || board1 == [1, 4, 7] ||
   board1 == [2, 5, 8] || board1 == [3, 6, 9]
  board1.each { |state| board_states[state - 1] = 'X' }
  puts "#{player1} win"
  break
end

我对ruby和一般的编码都是新手。如何按照rubocop的建议将上述代码重构为更简洁的代码?

rubocop建议您使用
Array\include>重构
if
条件

states=[[1,2,3]、[4,5,6]、[7,8,9]、[3,5,7]、[1,5,9]、[1,4,7]、[2,5,8]、[3,6,9]]
如果是州。包括?(董事会1)
每个{州}州[州-1]='X'}
放置“#{player1}赢”
打破
结束

在提供示例的文档中,这个问题更合适: