Module: ComposableStateMachine::CallbackRunner

Defined in:
lib/composable_state_machine/callback_runner.rb

Overview

Mixin module that runs callbacks with self pointing to the object the module is included in.

Instance Method Summary collapse

Instance Method Details

#run_state_machine_callback(callback, *args) ⇒ Object

Runs a callback with self pointing to the object the module is included in.

Parameters:

  • callback (Proc, Method, UnboundMethod, ...)

    the callback. Unbound methods will be bound to the object the mixin is included in.

  • args (Array<Object>)

    parameters to pass to the callback.

Returns:

  • (Object)

    the result of the callback



11
12
13
14
15
16
# File 'lib/composable_state_machine/callback_runner.rb', line 11

def run_state_machine_callback(callback, *args)
  if callback.respond_to?(:bind)
    callback = callback.bind(self)
  end
  instance_exec(*args, &callback)
end