Module: MM::PegsFactory
- Defined in:
- lib/games/mastermind/pegs_factory.rb
Class Method Summary collapse
- .build_empty_pegs(rows = 12, cols = 4, pegs_class = Pegs) ⇒ Object
- .create_empty_peg(row, col, display_value = nil, peg_class = Peg) ⇒ Object
Class Method Details
.build_empty_pegs(rows = 12, cols = 4, pegs_class = Pegs) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/games/mastermind/pegs_factory.rb', line 6 def self.build_empty_pegs(rows = 12, cols = 4, pegs_class = Pegs) pegs = Array.new(rows) do Array.new(cols) end pegs.each_with_index do |element, row| element.each_index do |col| pegs[row][col] = create_empty_peg(row, col) end end pegs_class.new(collection_of_pegs: pegs) end |
.create_empty_peg(row, col, display_value = nil, peg_class = Peg) ⇒ Object
20 21 22 23 24 |
# File 'lib/games/mastermind/pegs_factory.rb', line 20 def self.create_empty_peg(row, col, display_value = nil, peg_class = Peg) peg_class.new(display_value: display_value, row: row, col: col ) end |