From 0f57a0c2085f8179e3f617aff495ea8f1f252529 Mon Sep 17 00:00:00 2001 From: murajun1978 Date: Thu, 30 Nov 2017 00:36:31 +0900 Subject: [PATCH] Refactoring --- lib/transport.rb | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/transport.rb b/lib/transport.rb index d930638..3fcb9d7 100644 --- a/lib/transport.rb +++ b/lib/transport.rb @@ -1,11 +1,27 @@ +# require 'stringio' + def transport(source) - array = source.split("\n").map {|s| s.split(" ")} - rows_count = array.first.count + transported_array = + source + .lines + .collect(&:split) + .transpose + .map(&joinNumber) + + output(transported_array) +end + +private - transported_array = [] - 0.upto(rows_count - 1) do |i| - transported_array << array.map {|a| a[i]} + def joinNumber + lambda { |num| num.join(' ') } end - transported_array.map {|s| s.join(" ")}.join("\n") -end \ No newline at end of file + def output(rows) + rows.join("\n") + + # This code failed test + # io = StringIO.new + # io.puts rows + # io.string + end