]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
extends: String#wrap_nonempty
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 15 Mar 2009 11:29:19 +0000 (12:29 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 15 Mar 2009 11:29:19 +0000 (12:29 +0100)
We sometimes want to wrap a nonempty String with a given prefix and
postfix. This method makes it a breeze.

lib/rbot/core/utils/extends.rb

index 42500ee0f9f45544823cd23918903e8d44dda36c..083f2b858087f23b6f0200876f872d79ab691340 100644 (file)
@@ -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