Class: Butler::IRC::Client::Listener
- Inherits:
-
Object
- Object
- Butler::IRC::Client::Listener
- Includes:
- Comparable
- Defined in:
- lib/butler/irc/client/listener.rb
Overview
Created by Butler::IRC::Client#subscribe() and similar methods
Constant Summary collapse
- AllSymbols =
[nil].freeze
Instance Attribute Summary collapse
-
#container ⇒ Object
Returns the value of attribute container.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#symbols ⇒ Object
readonly
Returns the value of attribute symbols.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Comparison is done by priority, higher priority comes first, so Listener.new(nil, -100) > Listener.new(nil, 100).
-
#call(*args) ⇒ Object
Invoke the listener, always passes self as first argument.
-
#initialize(symbols = nil, priority = 0, *args, &callback) ⇒ Listener
constructor
A new instance of Listener.
-
#unsubscribe ⇒ Object
will remove this listener from the clients dispatcher forever.
Constructor Details
#initialize(symbols = nil, priority = 0, *args, &callback) ⇒ Listener
Returns a new instance of Listener.
22 23 24 25 26 27 28 |
# File 'lib/butler/irc/client/listener.rb', line 22 def initialize(symbols=nil, priority=0, *args, &callback) @priority = priority @symbols = (symbols ? Array(symbols) : AllSymbols).freeze @args = args @callback = callback @container = nil end |
Instance Attribute Details
#container ⇒ Object
Returns the value of attribute container.
20 21 22 |
# File 'lib/butler/irc/client/listener.rb', line 20 def container @container end |
#priority ⇒ Object
Returns the value of attribute priority.
18 19 20 |
# File 'lib/butler/irc/client/listener.rb', line 18 def priority @priority end |
#symbols ⇒ Object (readonly)
Returns the value of attribute symbols.
19 20 21 |
# File 'lib/butler/irc/client/listener.rb', line 19 def symbols @symbols end |
Instance Method Details
#<=>(other) ⇒ Object
Comparison is done by priority, higher priority comes first, so Listener.new(nil, -100) > Listener.new(nil, 100)
37 38 39 |
# File 'lib/butler/irc/client/listener.rb', line 37 def <=>(other) other.priority <=> @priority end |
#call(*args) ⇒ Object
Invoke the listener, always passes self as first argument
49 50 51 |
# File 'lib/butler/irc/client/listener.rb', line 49 def call(*args) @callback.call(self, *(args+@args)) end |
#unsubscribe ⇒ Object
will remove this listener from the clients dispatcher forever
31 32 33 |
# File 'lib/butler/irc/client/listener.rb', line 31 def unsubscribe @container.unsubscribe(self) end |