From da2b5e7506967ef9d9a9e5547665d352be15c7dd Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 27 Dec 2014 21:11:09 +0600 Subject: [PATCH 1/2] Fix verbose code with a one liner --- plugins/category_generator.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/plugins/category_generator.rb b/plugins/category_generator.rb index c55d62f..9beef9b 100644 --- a/plugins/category_generator.rb +++ b/plugins/category_generator.rb @@ -153,16 +153,7 @@ ERR # Returns string # def category_links(categories) - categories = categories.sort!.map { |c| category_link c } - - case categories.length - when 0 - "" - when 1 - categories[0].to_s - else - "#{categories[0...-1].join(', ')}, #{categories[-1]}" - end + categories.sort.map { |c| category_link c }.join(', ') end # Outputs a single category as an link. From 326e3cda5954165848b8089613cedfd74b1760a1 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 27 Dec 2014 21:11:18 +0600 Subject: [PATCH 2/2] Should use << for string concatenation in Ruby --- plugins/category_generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/category_generator.rb b/plugins/category_generator.rb index 9beef9b..769a55b 100644 --- a/plugins/category_generator.rb +++ b/plugins/category_generator.rb @@ -174,8 +174,8 @@ ERR # Returns string def date_to_html_string(date) result = '' + date.strftime('%b').upcase + ' ' - result += date.strftime('%d ') - result += date.strftime('%Y ') + result << date.strftime('%d ') + result << date.strftime('%Y ') result end