replacing an element in nested array ruby

后端 未结 1 901
借酒劲吻你
借酒劲吻你 2021-01-26 19:25

I\'m having trouble locating where my issue is in my code. I want to replace specific elements with \'X\' if they show up on a bingo board:

class BingoBoard

  d         


        
1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-26 19:45

    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
    

    0 讨论(0)
提交回复
热议问题