From 909ea4c210000ad0a92e82a050a26ae260aadbc7 Mon Sep 17 00:00:00 2001 From: a14m Date: Sun, 29 Nov 2020 23:32:37 +0100 Subject: Add the basic Universe class --- CLI/ruby/lib/game_of_life/universe.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 CLI/ruby/lib/game_of_life/universe.rb (limited to 'CLI/ruby/lib') diff --git a/CLI/ruby/lib/game_of_life/universe.rb b/CLI/ruby/lib/game_of_life/universe.rb new file mode 100644 index 0000000..a8c9050 --- /dev/null +++ b/CLI/ruby/lib/game_of_life/universe.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "forwardable" + +module GameOfLife + class Universe + extend Forwardable + + attr_accessor :universe + def_delegators :@universe, :[] + + # Initialize the empty initial universe 2D array + # @param width [Integer] the width of the universe array + # @param height [Integer] the height of the universe array + def initialize(width:, height:) + @universe = Array.new(height) { Array.new(width) } + end + + # Representation of the game of life universe + # @return [String] representing the current state + # @see ::GameOfLife::Cell#to_s + def to_s + @universe.map(&:join).join("\n") + end + end +end -- cgit v1.2.3