Class: Surrogate::Endower
- Inherits:
-
Object
- Object
- Surrogate::Endower
- Defined in:
- lib/surrogate/endower.rb
Overview
Adds surrogate behaviour to your class / singleton class / instances
please refactor me! …may not be possible :( Can we move all method definitions into this class?
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .add_hook(&block) ⇒ Object
- .endow(klass, options, &block) ⇒ Object
- .hooks ⇒ Object
- .uninitialized_instance_for(surrogate_class) ⇒ Object
Instance Method Summary collapse
- #endow ⇒ Object
-
#initialize(klass, options, &block) ⇒ Endower
constructor
A new instance of Endower.
Constructor Details
#initialize(klass, options, &block) ⇒ Endower
Returns a new instance of Endower.
30 31 32 |
# File 'lib/surrogate/endower.rb', line 30 def initialize(klass, , &block) self.klass, self., self.block = klass, , block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
28 29 30 |
# File 'lib/surrogate/endower.rb', line 28 def block @block end |
#klass ⇒ Object
Returns the value of attribute klass
28 29 30 |
# File 'lib/surrogate/endower.rb', line 28 def klass @klass end |
#options ⇒ Object
Returns the value of attribute options
28 29 30 |
# File 'lib/surrogate/endower.rb', line 28 def @options end |
Class Method Details
.add_hook(&block) ⇒ Object
16 17 18 |
# File 'lib/surrogate/endower.rb', line 16 def self.add_hook(&block) hooks << block end |
.endow(klass, options, &block) ⇒ Object
24 25 26 |
# File 'lib/surrogate/endower.rb', line 24 def self.endow(klass, , &block) new(klass, , &block).endow end |
.hooks ⇒ Object
20 21 22 |
# File 'lib/surrogate/endower.rb', line 20 def self.hooks @hooks ||= [] end |
.uninitialized_instance_for(surrogate_class) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/surrogate/endower.rb', line 8 def self.uninitialized_instance_for(surrogate_class) instance = surrogate_class.allocate hatchery = surrogate_class.instance_variable_get :@hatchery surrogate_class.last_instance = instance instance.instance_variable_set :@hatchling, Hatchling.new(instance, hatchery) instance end |
Instance Method Details
#endow ⇒ Object
34 35 36 37 |
# File 'lib/surrogate/endower.rb', line 34 def endow endow_klass endow_singleton_class end |