Fix verbose code with a one liner

This commit is contained in:
Nathan Broadbent 2014-12-27 21:11:09 +06:00
parent fbc3c0b544
commit da2b5e7506

View File

@ -153,16 +153,7 @@ ERR
# Returns string # Returns string
# #
def category_links(categories) def category_links(categories)
categories = categories.sort!.map { |c| category_link c } categories.sort.map { |c| category_link c }.join(', ')
case categories.length
when 0
""
when 1
categories[0].to_s
else
"#{categories[0...-1].join(', ')}, #{categories[-1]}"
end
end end
# Outputs a single category as an <a> link. # Outputs a single category as an <a> link.