From e161f375236a6fdc5cc0cb20cfbc51456e8e904b Mon Sep 17 00:00:00 2001 From: Rikuoh Date: Wed, 31 Jul 2024 23:52:23 +0900 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=81=EF=BC=81=EF=BC=81?= =?UTF-8?q?=EF=BC=81=EF=BC=81=EF=BC=81=EF=BC=81=EF=BC=81=EF=BC=81=EF=BC=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wc.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wc.rb b/wc.rb index cd3d2c6..ccde259 100644 --- a/wc.rb +++ b/wc.rb @@ -9,7 +9,7 @@ def main max_widths = calculate_max_widths(total_stat) file_stats << total_stat if filenames.size > 1 - file_stats.each { |file_stat| puts format_result(file_stat, max_widths, options).join(' ') } + file_stats.each { |file_stat| puts format_row(file_stat, max_widths, options) } end def parse_options @@ -50,11 +50,11 @@ def calculate_max_widths(total_stat) %i[lines words bytes].to_h { |key| [key, total_stat[key].to_s.length] } end -def format_result(stats, max_widths, options) +def format_row(stats, max_widths, options) result = %i[lines words bytes].filter_map do |key| stats[key].to_s.rjust(max_widths[key]) if options[key] end - result << stats[:filename] + [*result, stats[:filename]].join(' ') end main