diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-06 22:39:57 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-06 22:39:57 +0000 |
commit | 6b371332a5de74de6582cfdee56aac4779f4f2a6 (patch) | |
tree | 7c2390b5b77816bdd3c10ade171465acdfc1bab6 /lib | |
parent | 4d193a6c8719351147faad15e9a91d391df94952 (diff) |
Improved inspect methods all around
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rbot/botuser.rb | 2 | ||||
-rw-r--r-- | lib/rbot/irc.rb | 14 | ||||
-rw-r--r-- | lib/rbot/ircbot.rb | 32 | ||||
-rw-r--r-- | lib/rbot/plugins.rb | 13 |
4 files changed, 55 insertions, 6 deletions
diff --git a/lib/rbot/botuser.rb b/lib/rbot/botuser.rb index dc137154..9f2620dc 100644 --- a/lib/rbot/botuser.rb +++ b/lib/rbot/botuser.rb @@ -321,7 +321,7 @@ class Bot # Inspection
def inspect
- str = "<#{self.class}:#{'0x%08x' % self.object_id}"
+ str = self.__to_s__[0..-2]
str << " (transient)" if @transient
str << ":"
str << " @username=#{@username.inspect}"
diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb index 02835b36..86ca0fab 100644 --- a/lib/rbot/irc.rb +++ b/lib/rbot/irc.rb @@ -30,6 +30,10 @@ class Object return true if self.respond_to? :empty and self.empty?
return false
end
+
+ # We alias the to_s method to __to_s__ to make
+ # it accessible in all classes
+ alias :__to_s__ :to_s
end
# The Irc module is used to keep all IRC-related classes
@@ -89,7 +93,7 @@ module Irc # A Casemap is represented by its lower/upper mappings
#
def inspect
- "#<#{self.class}:#{'0x%x'% self.object_id}: #{upper.inspect} ~(#{self})~ #{lower.inspect}>"
+ self.__to_s__[0..-2] + " #{upper.inspect} ~(#{self})~ #{lower.inspect}>"
end
# As a String we return our name
@@ -355,7 +359,7 @@ class ArrayOf < Array end
def inspect
- "#<#{self.class}[#{@element_class}]:#{'0x%x' % self.object_id}: #{super}>"
+ self.__to_s__[0..-2].sub(/:[^:]+$/,"[#{@element_class}]\\0") + " #{super}>"
end
# Private method to check the validity of the elements passed to it
@@ -688,7 +692,7 @@ module Irc # one), its casemap and the nick, user and host part
#
def inspect
- str = "<#{self.class}:#{'0x%x' % self.object_id}:"
+ str = self.__to_s__[0..-2]
str << " @server=#{@server}" if defined?(@server) and @server
str << " @nick=#{@nick.inspect} @user=#{@user.inspect}"
str << " @host=#{@host.inspect} casemap=#{casemap.inspect}"
@@ -1278,7 +1282,7 @@ module Irc alias :to_s :name
def inspect
- str = "<#{self.class}:#{'0x%x' % self.object_id}:"
+ str = self.__to_s__[0..-2]
str << " on server #{server}" if server
str << " @name=#{@name.inspect} @topic=#{@topic.text.inspect}"
str << " @users=[#{user_nicks.sort.join(', ')}]"
@@ -1477,7 +1481,7 @@ module Irc }
}
- str = "<#{self.class}:#{'0x%x' % self.object_id}:"
+ str = self.__to_s__[0..-2]
str << " @hostname=#{hostname}"
str << " @channels=#{chans}"
str << " @users=#{users}"
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 05e58de2..5cb9e4f3 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -178,6 +178,38 @@ class Bot myself.nick end + # bot inspection + # TODO multiserver + def inspect + ret = self.to_s[0..-2] + ret << ' version=' << $version.inspect + ret << ' botclass=' << botclass.inspect + ret << ' lang="' << lang.language + if defined?(GetText) + ret << '/' << locale + end + ret << '"' + ret << ' nick=' << nick.inspect + ret << ' server=' + if server + ret << (server.to_s + (socket ? + ' [' << socket.server_uri.to_s << ']' : '')).inspect + unless server.channels.empty? + ret << " channels=" + ret << server.channels.map { |c| + "%s%s" % [c.modes_of(nick).map { |m| + server.prefix_for_mode(m) + }, c.name] + }.inspect + end + else + ret << '(none)' + end + ret << ' plugins=' << plugins.inspect + ret << ">" + end + + # create a new Bot with botclass +botclass+ def initialize(botclass, params = {}) # Config for the core bot diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb index 5ad1ebb1..12fade3e 100644 --- a/lib/rbot/plugins.rb +++ b/lib/rbot/plugins.rb @@ -369,6 +369,19 @@ module Plugins bot_associate(nil) end + def inspect + ret = self.to_s[0..-2] + ret << ' corebotmodules=' + ret << @botmodules[:CoreBotModule].map { |m| + m.name + }.inspect + ret << ' plugins=' + ret << @botmodules[:Plugin].map { |m| + m.name + }.inspect + ret << ">" + end + # Reset lists of botmodules def reset_botmodule_lists @botmodules[:CoreBotModule].clear |