Class: Unbound::CallbackArray

Inherits:
Array
  • Object
show all
Defined in:
lib/unbound/callback_array.rb

Instance Method Summary collapse

Instance Method Details

#add_callback(*cbs) { ... } ⇒ Object

Registers one or more callbacks

Parameters:

  • cbs (Array<#call>)

    A splat of procs to register as callbacks

Yields:

  • cb_block A block to register as a callback

Raises:

  • (ArgumentError)

    if no callbacks are provided



7
8
9
10
11
# File 'lib/unbound/callback_array.rb', line 7

def add_callback(*cbs, &cb_block)
  cbs.push(cb_block) unless cb_block.nil?
  raise(ArgumentError.new("Missing callback")) if cbs.empty?
  concat(cbs)
end

#call(*args) ⇒ Object

Calls each registered callback with the provided arguments

Parameters:

  • args (Array)

    A splat of arguments to pass to each callback via #call



15
16
17
18
19
# File 'lib/unbound/callback_array.rb', line 15

def call(*args)
  each do |cb|
    cb.call(*args)
  end
end