diff options
Diffstat (limited to 'CLI/ruby/lib')
| -rw-r--r-- | CLI/ruby/lib/game_of_life/cell.rb | 20 | ||||
| -rw-r--r-- | CLI/ruby/lib/game_of_life/generators/input.rb | 2 |
2 files changed, 11 insertions, 11 deletions
diff --git a/CLI/ruby/lib/game_of_life/cell.rb b/CLI/ruby/lib/game_of_life/cell.rb index 3f8fcd4..8997b38 100644 --- a/CLI/ruby/lib/game_of_life/cell.rb +++ b/CLI/ruby/lib/game_of_life/cell.rb @@ -5,21 +5,21 @@ module GameOfLife # Class representing a cell in the GemeOfLife universe # @!attribute [r] alive # @return [True | False] the living state of the cell - # @!attribute [r] pos_x + # @!attribute [r] x # @return [Integer] the X-axis position of the cell in the universe - # @!attribute [r] pos_y + # @!attribute [r] y # @return [Integer] the Y-axis position of the cell in the universe class Cell - attr_reader :alive, :pos_x, :pos_y + attr_reader :alive, :x, :y # Initialize a cell in the game of life universe # @param alive [True|False] boolean indicating if the cell is considered alive - # @param pos_x [Integer] the x position on the cyclic universe plane - # @param pos_y [Integer] the y position on the cyclic universe plane - def initialize(alive:, pos_x:, pos_y:) + # @param x [Integer] the x position on the cyclic universe plane + # @param y [Integer] the y position on the cyclic universe plane + def initialize(alive:, x:, y:) @alive = alive - @pos_x = pos_x - @pos_y = pos_y + @x = x + @y = y end # Representation of a cell @@ -69,7 +69,7 @@ module GameOfLife # @see #survive! # @see #die! private def repopulate! - self.class.new(pos_x: @pos_x, pos_y: @pos_y, alive: true) + self.class.new(x: x, y: y, alive: true) end # Helper method to define the language used in GameOfLife @@ -86,7 +86,7 @@ module GameOfLife # @see #repopulate! # @see #survive! private def die! - dead? ? self : self.class.new(pos_x: @pos_x, pos_y: @pos_y, alive: false) + dead? ? self : self.class.new(x: x, y: y, alive: false) end end end diff --git a/CLI/ruby/lib/game_of_life/generators/input.rb b/CLI/ruby/lib/game_of_life/generators/input.rb index cbde075..05aab1c 100644 --- a/CLI/ruby/lib/game_of_life/generators/input.rb +++ b/CLI/ruby/lib/game_of_life/generators/input.rb @@ -34,7 +34,7 @@ module GameOfLife universe = GameOfLife::Universe.new(height: height, width: width) (0...height).each do |i| (0...width).each do |j| - cell = { pos_x: j, pos_y: i, alive: parsed_input.fetch(i, nil)&.fetch(j, nil) } + cell = { x: j, y: i, alive: parsed_input.fetch(i, nil)&.fetch(j, nil) } universe[i][j] = ::GameOfLife::Cell.new(cell) end end |
