From 553cde4d33c860a5490691117e414e586a685ae9 Mon Sep 17 00:00:00 2001 From: a14m Date: Mon, 30 Nov 2020 12:39:35 +0100 Subject: 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 --- CLI/ruby/lib/game_of_life/cell.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'CLI/ruby/lib') 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 -- cgit v1.2.3