Class: MPV::Callback

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(object, method) ⇒ Callback



13
14
15
16
# File 'lib/mpv/callback.rb', line 13

def initialize(object, method)
  @object = object
  @method = method
end

Instance Attribute Details

#methodSymbol



9
10
11
# File 'lib/mpv/callback.rb', line 9

def method
  @method
end

#objectObject



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