diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-03-15 12:29:19 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-03-15 12:29:19 +0100 |
commit | d27b95318e87267b095a5a9dcf80aabafca87601 (patch) | |
tree | ed21e9bab281db7005cfaa1e04f28774822d15e4 | |
parent | 18da28adc1a0559c92f81185fc96ef41a0fd57a3 (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.
-rw-r--r-- | lib/rbot/core/utils/extends.rb | 10 |
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 |