Module: Flows::Plugin::ImplicitInit
- Included in:
- Railway, SharedContextPipeline
- Defined in:
- lib/flows/plugin/implicit_init.rb
Overview
Note:
This module must be injected into target class using extend
, not include
.
Note:
Class inheritance is supported: each child class will inherit behaviour, but not data.
Class extension with method MyClass.call
which works like MyClass.new.call
.
Instance Attribute Summary collapse
-
#default_instance ⇒ Object
readonly
Contains memoized instance of a host class or
nil
.
Instance Method Summary collapse
-
#call(*args, **kwargs, &block) ⇒ Object
Creates an instance of a host class by calling
new
without arguments and calls#call
method on the instance with provided parameters and block.
Instance Attribute Details
#default_instance ⇒ Object (readonly)
Contains memoized instance of a host class or nil
.
30 31 32 |
# File 'lib/flows/plugin/implicit_init.rb', line 30 def default_instance @default_instance end |
Instance Method Details
#call(*args, **kwargs, &block) ⇒ Object
Creates an instance of a host class by calling new
without arguments and
calls #call
method on the instance with provided parameters and block.
After first invocation the instance will be memoized in #default_instance.
Child classes have separate default instances.
38 39 40 41 42 |
# File 'lib/flows/plugin/implicit_init.rb', line 38 def call(*args, **kwargs, &block) @default_instance ||= new default_instance.call(*args, **kwargs, &block) end |