Class: StimulusPlumbers::Plumber::Dispatcher::InstanceExec
- Inherits:
-
Object
- Object
- StimulusPlumbers::Plumber::Dispatcher::InstanceExec
- Defined in:
- lib/stimulus_plumbers/plumber/dispatcher.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#kwargs ⇒ Object
readonly
Returns the value of attribute kwargs.
Instance Method Summary collapse
- #call(target) ⇒ Object
-
#initialize(block, *args, **kwargs) ⇒ InstanceExec
constructor
A new instance of InstanceExec.
Constructor Details
#initialize(block, *args, **kwargs) ⇒ InstanceExec
Returns a new instance of InstanceExec.
39 40 41 42 43 44 |
# File 'lib/stimulus_plumbers/plumber/dispatcher.rb', line 39 def initialize(block, *args, **kwargs) @block = block @args = args @kwargs = kwargs validate! end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
37 38 39 |
# File 'lib/stimulus_plumbers/plumber/dispatcher.rb', line 37 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
37 38 39 |
# File 'lib/stimulus_plumbers/plumber/dispatcher.rb', line 37 def block @block end |
#kwargs ⇒ Object (readonly)
Returns the value of attribute kwargs.
37 38 39 |
# File 'lib/stimulus_plumbers/plumber/dispatcher.rb', line 37 def kwargs @kwargs end |
Instance Method Details
#call(target) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/stimulus_plumbers/plumber/dispatcher.rb', line 46 def call(target) accepts_args = block.arity.negative? ? args : args.take(block.arity) accepts_kwargs = block.parameters.any? { |type, _| %i[key keyreq keyrest].include?(type) } if accepts_kwargs target.instance_exec( *accepts_args, **kwargs, &block ) else target.instance_exec(*accepts_args, &block) end end |