Module: Flows::Util::InheritableSingletonVars::DupStrategy
- Defined in:
- lib/flows/util/inheritable_singleton_vars/dup_strategy.rb
Overview
If you change variables in a parent class after a child being defined it will have no effect on a child. Remember this when working in environments with tricky or experimental autoload mechanism.
Strategy which uses #dup
to copy variables to a child class.
Can be applied several times to the same class.
Can be applied in the middle of inheritance chain.
When your value is a custom class you may need to adjust #dup
behaviour.
It can be done using initialize_dup
method.
Unfortunately it's not documented well in the standard library.
So, this will help you.
Defined Under Namespace
Constant Summary collapse
- VAR_LIST_VAR_NAME =
:@inheritable_vars_with_dup
Class Method Summary collapse
-
.make_module(vars_with_default = {}) ⇒ Object
Generates a module which applies behaviour and defaults for singleton variables.
Class Method Details
.make_module(vars_with_default = {}) ⇒ Object
Variable names should look like :@var
or '@var'
.
Generates a module which applies behaviour and defaults for singleton variables.
81 82 83 84 85 86 87 |
# File 'lib/flows/util/inheritable_singleton_vars/dup_strategy.rb', line 81 def make_module(vars_with_default = {}) Module.new.tap do |mod| mod.instance_variable_set(VAR_LIST_VAR_NAME, vars_with_default.keys.map(&:to_sym)) init_vars(mod, vars_with_default) mod.extend Injector end end |