Module: ParallelAncestry::Inheritance
- Extended by:
- Module::Cluster
- Defined in:
- lib/parallel_ancestry/inheritance.rb
Defined Under Namespace
Modules: ModuleSubclassInheritance
Instance Method Summary collapse
-
#initialize_base_instance_for_extend(inheriting_instance) ⇒ Object
initialize_base_instance_for_extend #.
-
#initialize_base_instance_for_include(inheriting_instance) ⇒ Object
initialize_base_instance_for_include #.
-
#initialize_inheritance(instance) ⇒ Object
initialize_inheritance #.
-
#initialize_inheritance_for_module! ⇒ Object
initialize_inheritance_for_module! #.
-
#initialize_inheriting_instance(parent_instance, inheriting_instance, for_subclass = false, is_extending = false) ⇒ Object
initialize_inheriting_instance #.
Instance Method Details
#initialize_base_instance_for_extend(inheriting_instance) ⇒ Object
initialize_base_instance_for_extend #
75 76 77 78 79 80 81 |
# File 'lib/parallel_ancestry/inheritance.rb', line 75 def initialize_base_instance_for_extend( inheriting_instance ) # Hook for extended module to redefine - nothing to do. return inheriting_instance end |
#initialize_base_instance_for_include(inheriting_instance) ⇒ Object
initialize_base_instance_for_include #
64 65 66 67 68 69 |
# File 'lib/parallel_ancestry/inheritance.rb', line 64 def initialize_base_instance_for_include( inheriting_instance ) # Initialize for future inheriting instances. return initialize_inheritance( inheriting_instance ) end |
#initialize_inheritance(instance) ⇒ Object
initialize_inheritance #
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/parallel_ancestry/inheritance.rb', line 91 def initialize_inheritance( instance ) unless @initialized_inheritance_for_instance[ instance ] inheritance_module = self if instance.is_a?( ::Class ) instance.extend( ::Module::Cluster ) instance.cluster( :parallel_ancestry ).subclass do |inheriting_subclass| inheritance_module.initialize_inheriting_instance( instance, inheriting_subclass, true ) inheritance_module.initialize_inheritance( inheriting_subclass ) end else instance.extend( ::Module::Cluster ) instance.cluster( :parallel_ancestry ).before_include do |inheriting_module| inheritance_module.initialize_inheriting_instance( instance, inheriting_module ) inheritance_module.initialize_inheritance( inheriting_module ) end instance.cluster( :parallel_ancestry ).before_extend do |inheriting_module| inheritance_module.initialize_inheriting_instance( instance, inheriting_module, false, true ) end end @initialized_inheritance_for_instance[ instance ] = true end end |
#initialize_inheritance_for_module! ⇒ Object
initialize_inheritance_for_module! #
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/parallel_ancestry/inheritance.rb', line 36 def initialize_inheritance_for_module! @initialized_inheritance_for_instance = { } extend ::Module::Cluster # When inheritance module is included in another module: cluster( :parallel_ancestry ).before_include do |base_instance| initialize_base_instance_for_include( base_instance ) end # When inheritance module is used to extend another module: cluster( :parallel_ancestry ).before_extend do |base_instance| initialize_base_instance_for_extend( base_instance ) end return self end |
#initialize_inheriting_instance(parent_instance, inheriting_instance, for_subclass = false, is_extending = false) ⇒ Object
initialize_inheriting_instance #
131 132 133 134 135 136 137 |
# File 'lib/parallel_ancestry/inheritance.rb', line 131 def initialize_inheriting_instance( parent_instance, inheriting_instance, for_subclass = false, is_extending = false ) # Hook for extended module to redefine - nothing to do. return inheriting_instance end |