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 | |
| 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')
| -rw-r--r-- | CLI/ruby/.rubocop.yml | 3 | ||||
| -rw-r--r-- | CLI/ruby/lib/game_of_life/cell.rb | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/CLI/ruby/.rubocop.yml b/CLI/ruby/.rubocop.yml index 59385a2..12f8fd8 100644 --- a/CLI/ruby/.rubocop.yml +++ b/CLI/ruby/.rubocop.yml @@ -11,6 +11,9 @@ Layout/LineLength: Style/AccessModifierDeclarations: EnforcedStyle: inline +Style/Alias: + EnforcedStyle: prefer_alias_method + Style/BlockDelimiters: Exclude: - 'spec/**/*' 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 |
