替换嵌套数组中的元素 ruby

replacing an element in nested array ruby

我无法在我的代码中找到我的问题所在。如果特定元素出现在宾果板上,我想用 'X' 替换它们:

class BingoBoard

  def initialize(board)
    @bingo_board = board
  end

  def number_letter

    @letter = ['B','I','N','G','O'].sample
    @number = rand(1..100)

  end

  def checker
    @number
    @bingo_board.map! do |n|

      if n.include?(@number)

        n.map! { |x| x == @number ? 'X' : x}

      else

        n

      end
    end

  end

end

这是我用来查看我的代码是否为 运行 的测试,但 X 从未出现,我现在已经多次查看我的代码,但无法弄清楚为什么... :

board = [[47, 44, 71, 8, 88],
        [22, 69, 75, 65, 73],
        [83, 85, 97, 89, 57],
        [25, 31, 96, 68, 51],
        [75, 70, 54, 80, 83]]

new_game = BingoBoard.new(board)

new_game.checker

如果有人能提供我所缺少或没有看到的见解,我将不胜感激!

class BingoBoard

  def initialize(board)
    @bingo_board = board
  end

  def number_letter

    @letter = ['B','I','N','G','O'].sample
    @number = rand(1..100)

  end

  def checker
    number_letter
    @bingo_board.each do |n|
      index = n.index(@number)
      n[index] = 'X' unless index.nil?
    end

  end

end