使宾果游戏板数组作为输出红宝石整齐地显示在行中



你好,我有以下宾果游戏代码,为返回的数字标记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_letter
    @bingo_board.map! do |n|
      if n.include?(@number)    #cleaned up code from the initial solution.
        n.map! { |x| x == @number ? 'X' : x}
      else
        n
      end
    end
  end
end

我的问题是我如何更改我的代码,以便在使用测试代码时:

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

它将整齐地看起来像irb中的宾果游戏板。

现在它看起来像:

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

.map { |block| puts block.inspect }附加到new_game.checker调用。

最新更新