Class: Volt::Listener
Overview
Listeners are returned from #on on a class with Eventable included. Listeners can be stopped by calling #remove
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(klass, event, callback) ⇒ Listener
constructor
A new instance of Listener.
- #inspect ⇒ Object
- #remove ⇒ Object
Constructor Details
#initialize(klass, event, callback) ⇒ Listener
Returns a new instance of Listener.
5 6 7 8 9 |
# File 'lib/volt/reactive/eventable.rb', line 5 def initialize(klass, event, callback) @klass = klass @event = event @callback = callback end |
Instance Method Details
#call(*args) ⇒ Object
11 12 13 |
# File 'lib/volt/reactive/eventable.rb', line 11 def call(*args) @callback.call(*args) unless @removed end |
#inspect ⇒ Object
25 26 27 |
# File 'lib/volt/reactive/eventable.rb', line 25 def inspect "<Listener:#{object_id} event=#{@event}>" end |
#remove ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/volt/reactive/eventable.rb', line 15 def remove @removed = true @klass.remove_listener(@event, self) # Make things easier on the GC @klass = nil @callback = nil end |