]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
IRC framework: Server#to_s must always return a String
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 29 Sep 2010 23:37:05 +0000 (01:37 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 29 Sep 2010 23:37:05 +0000 (01:37 +0200)
Having Server#to_s alias the hostname would cause problems when the
hostname was nil (e.g. after a disconnect). Fix by making sure that to_s
always returns a string instead.

lib/rbot/irc.rb

index 326e25ef2f1d624884c6d181c11da4002e9700c2..c57b252f58973801f7f5b8a6e234a56903c1185e 100644 (file)
@@ -1525,7 +1525,6 @@ module Irc
   class Server
 
     attr_reader :hostname, :version, :usermodes, :chanmodes
-    alias :to_s :hostname
     attr_reader :supports, :capabilities
 
     attr_reader :channels, :users
@@ -1556,6 +1555,10 @@ module Irc
       str << ">"
     end
 
+    def to_s
+      hostname.nil? ? "<no hostname>" : hostname
+    end
+
     # Create a new Server, with all instance variables reset to nil (for
     # scalar variables), empty channel and user lists and @supports
     # initialized to the default values for all known supported features.