diff options
| author | a14m <[email protected]> | 2020-11-29 23:32:37 +0100 |
|---|---|---|
| committer | a14m <[email protected]> | 2020-11-29 23:37:31 +0100 |
| commit | 909ea4c210000ad0a92e82a050a26ae260aadbc7 (patch) | |
| tree | af4a71a173b605572d17197f40a23f818ee67afb /CLI/ruby/lib | |
| parent | 5555d4122fb96a2d52a887fbffa365c709056986 (diff) | |
Add the basic Universe class
Diffstat (limited to 'CLI/ruby/lib')
| -rw-r--r-- | CLI/ruby/lib/game_of_life/universe.rb | 26 |
1 files changed, 26 insertions, 0 deletions
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 |
