Class: StimulusPlumbers::Plumber::Dispatcher::MethodCall
- Inherits:
-
Object
- Object
- StimulusPlumbers::Plumber::Dispatcher::MethodCall
- Includes:
- CallableInspector
- Defined in:
- lib/stimulus_plumbers/plumber/dispatcher/method_call.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#kwargs ⇒ Object
readonly
Returns the value of attribute kwargs.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
Instance Method Summary collapse
- #call(target) ⇒ Object
-
#initialize(method_name, *args, **kwargs) ⇒ MethodCall
constructor
A new instance of MethodCall.
Constructor Details
#initialize(method_name, *args, **kwargs) ⇒ MethodCall
Returns a new instance of MethodCall.
11 12 13 14 15 16 |
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 11 def initialize(method_name, *args, **kwargs) @method_name = method_name @args = args @kwargs = kwargs validate! end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
9 10 11 |
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 9 def args @args end |
#kwargs ⇒ Object (readonly)
Returns the value of attribute kwargs.
9 10 11 |
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 9 def kwargs @kwargs end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
9 10 11 |
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 9 def method_name @method_name end |
Instance Method Details
#call(target) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/stimulus_plumbers/plumber/dispatcher/method_call.rb', line 18 def call(target) raise NotImplementedError, "#{method_name.inspect} not implemented" unless target.respond_to?(method_name, true) method_call = target.method(method_name) dispatched = args_for(method_call) accepts_kwargs?(method_call) ? method_call.call(*dispatched, **kwargs) : method_call.call(*dispatched) end |