summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-03-15 12:29:19 +0100
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-03-15 12:29:19 +0100
commitd27b95318e87267b095a5a9dcf80aabafca87601 (patch)
treeed21e9bab281db7005cfaa1e04f28774822d15e4 /lib
parent18da28adc1a0559c92f81185fc96ef41a0fd57a3 (diff)
extends: String#wrap_nonempty
We sometimes want to wrap a nonempty String with a given prefix and postfix. This method makes it a breeze.
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/core/utils/extends.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb
index 42500ee0..083f2b85 100644
--- a/lib/rbot/core/utils/extends.rb
+++ b/lib/rbot/core/utils/extends.rb
@@ -283,6 +283,16 @@ class ::String
def ircify_html_title
self.get_html_title.ircify_html rescue nil
end
+
+ # This method is used to wrap a nonempty String by adding
+ # the prefix and postfix
+ def wrap_nonempty(pre, post, opts={})
+ if self.empty?
+ String.new
+ else
+ "#{pre}#{self}#{post}"
+ end
+ end
end