From ba95efbf88ecc51644e918b14542e173dd117b0a Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 18 Dec 2016 17:03:49 -0800 Subject: [PATCH] [2016][ruby][18.0] Row#initialize --- 2016/ruby/day_18.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 2016/ruby/day_18.rb diff --git a/2016/ruby/day_18.rb b/2016/ruby/day_18.rb new file mode 100644 index 0000000..9e13bcb --- /dev/null +++ b/2016/ruby/day_18.rb @@ -0,0 +1,18 @@ +class Row + INPUT_MAP = { ?. => :safe, ?^ => :trap } + + attr_reader :tiles + + def initialize(input) + @tiles = input.chars.map {|char| INPUT_MAP.fetch(char) } + end +end + +require 'minitest/autorun' + +class TestRow < Minitest::Test + def test_row + row = Row.new('..^^.') + assert_equal %i[ safe safe trap trap safe ], row.tiles + end +end