]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
HTML IRCification: don't modify the receiver; provide an ircify_html! method to modif...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 8 Apr 2007 21:11:31 +0000 (21:11 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 8 Apr 2007 21:11:31 +0000 (21:11 +0000)
lib/rbot/core/utils/extends.rb

index b812a6766f7f587a55f823f7bdbe3814ca301926..950ad678b8cd92a45429a39e1924b51e3cd2d6cf 100644 (file)
@@ -56,7 +56,7 @@ class ::String
   # stripped off and some of it converted to IRC formatting
   #
   def ircify_html
-    txt = self
+    txt = self.dup
 
     # remove scripts
     txt.gsub!(/<script(?:\s+[^>]*)?>.*?<\/script>/im, "")
@@ -108,6 +108,14 @@ class ::String
     return txt.strip
   end
 
+  # As above, but modify the receiver
+  #
+  def ircify_html!
+    old_hash = self.hash
+    replace self.ircify_html
+    return self unless self.hash == old_hash
+  end
+
   # This method will strip all HTML crud from the receiver
   #
   def riphtml