Class: MPV::Callback
- Inherits:
-
Object
- Object
- MPV::Callback
- Defined in:
- lib/mpv/callback.rb
Overview
Encapsulates an object-method pair that will be invoked whenever an Client receives an event.
Instance Attribute Summary collapse
-
#method ⇒ Symbol
The method that the callback will invoke.
-
#object ⇒ Object
The object that the callback will be issued to.
Instance Method Summary collapse
-
#dispatch!(event) ⇒ void
Dispatches the callback.
-
#initialize(object, method) ⇒ Callback
constructor
A new instance of Callback.
-
#valid? ⇒ Boolean
Determines the validity of the instantiated callback.
Constructor Details
#initialize(object, method) ⇒ Callback
Returns a new instance of Callback.
13 14 15 16 |
# File 'lib/mpv/callback.rb', line 13 def initialize(object, method) @object = object @method = method end |
Instance Attribute Details
#method ⇒ Symbol
Returns the method that the callback will invoke.
9 10 11 |
# File 'lib/mpv/callback.rb', line 9 def method @method end |
#object ⇒ Object
Returns the object that the callback will be issued to.
6 7 8 |
# File 'lib/mpv/callback.rb', line 6 def object @object end |
Instance Method Details
#dispatch!(event) ⇒ void
This method returns an undefined value.
Dispatches the callback. Does nothing unless #valid? is true.
29 30 31 32 33 |
# File 'lib/mpv/callback.rb', line 29 def dispatch!(event) return unless valid? object.send method, event end |
#valid? ⇒ Boolean
Determines the validity of the instantiated callback. A callback is said to be valid if the object responds to the given method and the method has an arity of 1 (for the event data).
22 23 24 |
# File 'lib/mpv/callback.rb', line 22 def valid? object.respond_to?(method) && object.method(method).arity == 1 end |