使宾果板数组以整齐的行显示为输出红宝石

时间:2015-04-16 21:58:16

标签: ruby arrays

你好,我有以下宾果游戏代码,用于标记返回的数字:

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"]]

1 个答案:

答案 0 :(得分:1)

.map { |block| puts block.inspect }附加到new_game.checker来电。