From 5555d4122fb96a2d52a887fbffa365c709056986 Mon Sep 17 00:00:00 2001 From: a14m Date: Sun, 29 Nov 2020 23:32:06 +0100 Subject: Add the basic cell representation object --- CLI/ruby/lib/game_of_life.rb | 1 + CLI/ruby/lib/game_of_life/cell.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 CLI/ruby/lib/game_of_life/cell.rb (limited to 'CLI/ruby/lib') diff --git a/CLI/ruby/lib/game_of_life.rb b/CLI/ruby/lib/game_of_life.rb index c2e6845..7f70933 100644 --- a/CLI/ruby/lib/game_of_life.rb +++ b/CLI/ruby/lib/game_of_life.rb @@ -2,6 +2,7 @@ require "game_of_life/version" require "game_of_life/universe" +require "game_of_life/cell" module GameOfLife class Error < StandardError; end diff --git a/CLI/ruby/lib/game_of_life/cell.rb b/CLI/ruby/lib/game_of_life/cell.rb new file mode 100644 index 0000000..fe52263 --- /dev/null +++ b/CLI/ruby/lib/game_of_life/cell.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module GameOfLife + class Cell + attr_accessor :alive + + # Initialize a cell in the game of life universe + # @param alive [True|False] boolean indicating if the cell is considered alive + def initialize(alive:) + @alive = alive + end + + # Representation of a cell + # @return [String] if a cell is alive or an empty space + def to_s + return @alive ? "\u2588" : "\s" + end + end +end -- cgit v1.2.3