From d27b95318e87267b095a5a9dcf80aabafca87601 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 15 Mar 2009 12:29:19 +0100 Subject: extends: String#wrap_nonempty 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') 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 -- cgit v1.2.3