diff options
| author | a14m <[email protected]> | 2020-11-30 12:29:42 +0100 |
|---|---|---|
| committer | a14m <[email protected]> | 2020-11-30 12:30:07 +0100 |
| commit | 3f606207ab466d25601d6879f745dfb1890f025f (patch) | |
| tree | f4c5d436d0711a1cab41cfacc23877137f986e07 /CLI/ruby | |
| parent | 55dabbb7c98d9ded2bf94b8e3c81f6baa9806449 (diff) | |
Configure live/dead cells representation via CLI options
Diffstat (limited to 'CLI/ruby')
| -rwxr-xr-x | CLI/ruby/bin/game-of-life | 8 | ||||
| -rw-r--r-- | CLI/ruby/lib/game_of_life/cell.rb | 3 |
2 files changed, 10 insertions, 1 deletions
diff --git a/CLI/ruby/bin/game-of-life b/CLI/ruby/bin/game-of-life index 14f5647..4de4fd4 100755 --- a/CLI/ruby/bin/game-of-life +++ b/CLI/ruby/bin/game-of-life @@ -25,6 +25,12 @@ class CLI < Thor class_option "height", aliases: "-h", type: :numeric, banner: :HEIGHT, desc: "Specify the hight of generated universe. (default to terminal height)" + + class_option "dead-cell", type: :string, banner: :CHAR, default: "\s", + desc: "Specify the dead-cell representation" + + class_option "live-cell", type: :string, banner: :CHAR, default: "\u2588", + desc: "Specify the dead-cell representation" def start options_with_defaults = { "height" => IO.console.winsize[0], @@ -32,6 +38,8 @@ class CLI < Thor "seed" => rand(100_000), }.merge(options) + GameOfLife::Cell.const_set(:LIVE_CELL, options["live-cell"]) + GameOfLife::Cell.const_set(:DEAD_CELL, options["dead-cell"]) universe = GameOfLife::Generators::Input.new(options_with_defaults) puts universe end diff --git a/CLI/ruby/lib/game_of_life/cell.rb b/CLI/ruby/lib/game_of_life/cell.rb index 19a48e0..a02ff4a 100644 --- a/CLI/ruby/lib/game_of_life/cell.rb +++ b/CLI/ruby/lib/game_of_life/cell.rb @@ -15,9 +15,10 @@ module GameOfLife end # Representation of a cell + # 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 ? "\u2588" : "\s" + @alive ? LIVE_CELL : DEAD_CELL end end end |
