summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-07-16 00:32:46 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-07-16 00:32:46 +0200
commit8f8205310518e7b0626d657ba9667f7bfc745371 (patch)
tree8d7d9e8869b15da3757fa568886a7f5fe8cb62da
parent63a0599d92b453c025ce3e0ea133b7f6c1af6b7a (diff)
Dumpable definition of #any? and #all? methods for Channel#mode
Commit 847a977b228b35f5ab281a31dd3724a4db887dff "#any? and #all? methods for Channel#mode to check if modes are set" turned Channel into a non-marshallable object because of singleton methods. Revert the commit and define an ad-hoc ModeHash class with the any? and all? methods, to make Channel#mode of that class.
-rw-r--r--lib/rbot/irc.rb20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/rbot/irc.rb b/lib/rbot/irc.rb
index 0be26a00..4ad57d99 100644
--- a/lib/rbot/irc.rb
+++ b/lib/rbot/irc.rb
@@ -1102,6 +1102,16 @@ module Irc
end
+ # Hash of modes. Subclass of Hash that defines any? and all?
+ # to check if boolean modes (Type D) are set
+ class ModeHash < Hash
+ def any?(*ar)
+ !!ar.find { |m| s = m.to_sym ; self[s] && self[s].set? }
+ end
+ def all?(*ar)
+ !ar.find { |m| s = m.to_sym ; !(self[s] && self[s].set?) }
+ end
+ end
# Channel modes of type A manipulate lists
#
@@ -1358,15 +1368,7 @@ module Irc
}
# Flags
- @mode = {}
- class << @mode
- def any?(*ar)
- !!ar.find { |m| s = m.to_sym ; self[s] && self[s].set? }
- end
- def all?(*ar)
- !ar.find { |m| s = m.to_sym ; !(self[s] && self[s].set?) }
- end
- end
+ @mode = ModeHash.new
end
# Removes a user from the channel