diff options
-rw-r--r-- | lib/rbot/core/utils/utils.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/rbot/core/utils/utils.rb b/lib/rbot/core/utils/utils.rb index 77bdeecf..f9912ebb 100644 --- a/lib/rbot/core/utils/utils.rb +++ b/lib/rbot/core/utils/utils.rb @@ -723,6 +723,20 @@ module ::Irc return retval end + # Returns a comma separated list except for the last element + # which is joined in with specified conjunction + # + def Utils.comma_list(words, options={}) + defaults = { :join_with => ", ", :join_last_with => _(" and ") } + opts = defaults.merge(options) + + if words.size < 2 + words.last + else + [words[0..-2].join(opts[:join_with]), words.last].join(opts[:join_last_with]) + end + end + end end |