summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2009-03-03 08:44:20 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-03-03 20:52:12 +0100
commitab0c959bc7305d853e4a52b2a0f25a5fc78f4bfb (patch)
treeaacd57e8f5249e0971b4f5a942c97f1ec436ab19 /lib
parentd35f0c02e3662eb2d45cf5eb94000a9826dc7f70 (diff)
utils: add a helper method for creating comma separated lists
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/core/utils/utils.rb14
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