Module: Spotify::CallbackStruct

Defined in:
lib/hallon/ext/spotify.rb

Overview

Makes it easier binding callbacks safely to callback structs.

See Also:

  • add
  • remove

Instance Method Summary collapse

Instance Method Details

#[]=(member, callback) ⇒ Object

Before assigning [member]=(callback), inspect the arity of said callback and raise an ArgumentError if they don‘t match.

Raises:

  • ArgumentError if the arity of the given callback does not match the member


16
17
18
19
20
21
22
# File 'lib/hallon/ext/spotify.rb', line 16

def []=(member, callback)
  unless callback.arity < 0 or callback.arity == arity_of(member)
    raise ArgumentError, "#{member} callback takes #{arity_of(member)} arguments, was #{callback.arity}"
  else
    super
  end
end

#arity_of(member) ⇒ Integer (protected)


28
29
30
31
# File 'lib/hallon/ext/spotify.rb', line 28

def arity_of(member)
  fn = layout[member].type
  fn.param_types.size
end