Class: Lotus::Utils::Callbacks::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/utils/callbacks.rb

Overview

Proc callback It wraps an object that responds to #call

Since:

  • 0.1.0

Direct Known Subclasses

MethodCallback

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback) ⇒ Callback

Initialize by wrapping the given callback

Parameters:

  • callback (Object)

    the original callback that needs to be wrapped

Since:

  • 0.1.0



230
231
232
# File 'lib/lotus/utils/callbacks.rb', line 230

def initialize(callback)
  @callback = callback
end

Instance Attribute Details

#callbackObject (readonly)

Since:

  • 0.1.0



220
221
222
# File 'lib/lotus/utils/callbacks.rb', line 220

def callback
  @callback
end

Instance Method Details

#call(context, *args) ⇒ void, Object

Executes the callback within the given context and passing the given arguments.

Parameters:

  • context (Object)

    the context within we want to execute the callback.

  • args (Array)

    an array of arguments that will be available within the execution.

Returns:

  • (void, Object)

    It may return a value, it depends on the callback.

See Also:

Since:

  • 0.1.0



244
245
246
# File 'lib/lotus/utils/callbacks.rb', line 244

def call(context, *args)
  context.instance_exec(*args, &callback)
end