Class: Triton::Messenger::Listener
- Inherits:
-
Object
- Object
- Triton::Messenger::Listener
- Defined in:
- lib/triton/messenger.rb
Overview
The Listener class helps managing event triggering. It may not be used as its own.
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#once ⇒ Object
Returns the value of attribute once.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#fire(sender = nil, *args) ⇒ Object
Call the event listener passing through the
sender
and the additional args. -
#initialize(type, callback, once = false) ⇒ Listener
constructor
A new instance of Listener.
Constructor Details
#initialize(type, callback, once = false) ⇒ Listener
Returns a new instance of Listener.
86 87 88 89 90 |
# File 'lib/triton/messenger.rb', line 86 def initialize(type, callback, once=false) @type = type @callback = callback @once = once end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
84 85 86 |
# File 'lib/triton/messenger.rb', line 84 def callback @callback end |
#once ⇒ Object
Returns the value of attribute once.
84 85 86 |
# File 'lib/triton/messenger.rb', line 84 def once @once end |
#type ⇒ Object
Returns the value of attribute type.
84 85 86 |
# File 'lib/triton/messenger.rb', line 84 def type @type end |
Instance Method Details
#fire(sender = nil, *args) ⇒ Object
Call the event listener passing through the sender
and the additional args
93 94 95 96 97 98 99 |
# File 'lib/triton/messenger.rb', line 93 def fire(sender=nil, *args) @callback.call(sender, *args) if @once Messenger::remove_listener(self) end end |