diff options
| author | a14m <[email protected]> | 2020-11-30 12:39:35 +0100 |
|---|---|---|
| committer | a14m <[email protected]> | 2020-11-30 12:40:13 +0100 |
| commit | 553cde4d33c860a5490691117e414e586a685ae9 (patch) | |
| tree | 1b2f5eeb92d5ee3ff773a76e994aa1de5c4da3ea /CLI/ruby/lib | |
| parent | 3f606207ab466d25601d6879f745dfb1890f025f (diff) | |
Alias the method alive?
This provide the future flexibility when needing to override the method
to provide a custom behaviour it can be done and removing of the alias
and the rest of the class should be untouched
Diffstat (limited to 'CLI/ruby/lib')
| -rw-r--r-- | CLI/ruby/lib/game_of_life/cell.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/CLI/ruby/lib/game_of_life/cell.rb b/CLI/ruby/lib/game_of_life/cell.rb index a02ff4a..62cd3a1 100644 --- a/CLI/ruby/lib/game_of_life/cell.rb +++ b/CLI/ruby/lib/game_of_life/cell.rb @@ -4,6 +4,8 @@ module GameOfLife class Cell attr_accessor :alive, :pos_x, :pos_y + alias_method :alive?, :alive + # 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 @@ -18,7 +20,7 @@ module GameOfLife # Both LIVE_CELL, and DEAD_CELL constant are defined on the application start from the options # @return [String] if a cell is alive or an empty space def to_s - @alive ? LIVE_CELL : DEAD_CELL + alive? ? LIVE_CELL : DEAD_CELL end end end |
