Module: CMDx::Utils::Call
Overview
Utility module for invoking callable objects with different invocation strategies.
This module provides a unified interface for calling methods, procs, and other callable objects on target objects, handling the appropriate invocation method based on the callable type.
Instance Method Summary collapse
-
#invoke(target, callable, *args, **kwargs) {|Object| ... } ⇒ Object
Invokes a callable object on the target with the given arguments.
Instance Method Details
#invoke(target, callable, *args, **kwargs) {|Object| ... } ⇒ Object
Invokes a callable object on the target with the given arguments.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cmdx/utils/call.rb', line 39 def invoke(target, callable, *args, **kwargs, &) if callable.is_a?(Symbol) target.send(callable, *args, **kwargs, &) elsif callable.is_a?(Proc) target.instance_exec(*args, **kwargs, &callable) elsif callable.respond_to?(:call) callable.call(*args, **kwargs, &) else raise "cannot invoke #{callable}" end end |