Skip to content

Commit

Permalink
Helper function for making an english list out of an array.
Browse files Browse the repository at this point in the history
  • Loading branch information
tfe committed Feb 17, 2011
1 parent 3bf16c6 commit fc4a9d5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/duostack
Expand Up @@ -326,6 +326,18 @@ module Duostack
end
end

def sentencize(array, conjunction='or')
# http://stackoverflow.com/questions/2038787/join-array-contents-into-an-english-list
case array.length
when 0, 1
array.first.to_s
when 2
"#{array.first} #{conjunction} #{array.last}"
else
"#{array[0..-2].join(', ')}, #{conjunction} #{array.last}"
end
end

def debug(message)
puts message if ENV['DSDEBUG']
end
Expand Down

0 comments on commit fc4a9d5

Please sign in to comment.