Class: Surrogate::Hatchling
- Inherits:
-
Object
- Object
- Surrogate::Hatchling
- Defined in:
- lib/surrogate/hatchling.rb
Overview
This contains the unique behaviour for each instance It handles method invocation and records the appropriate information
Instance Attribute Summary collapse
-
#hatchery ⇒ Object
Returns the value of attribute hatchery.
-
#instance ⇒ Object
Returns the value of attribute instance.
Instance Method Summary collapse
- #api_methods ⇒ Object
-
#initialize(instance, hatchery) ⇒ Hatchling
constructor
A new instance of Hatchling.
- #invocations(method_name) ⇒ Object
- #invoke_method(method_name, args, &block) ⇒ Object
- #prepare_method(method_name, args, &block) ⇒ Object
Constructor Details
#initialize(instance, hatchery) ⇒ Hatchling
Returns a new instance of Hatchling.
11 12 13 |
# File 'lib/surrogate/hatchling.rb', line 11 def initialize(instance, hatchery) self.instance, self.hatchery = instance, hatchery end |
Instance Attribute Details
#hatchery ⇒ Object
Returns the value of attribute hatchery
9 10 11 |
# File 'lib/surrogate/hatchling.rb', line 9 def hatchery @hatchery end |
#instance ⇒ Object
Returns the value of attribute instance
9 10 11 |
# File 'lib/surrogate/hatchling.rb', line 9 def instance @instance end |
Instance Method Details
#api_methods ⇒ Object
15 16 17 |
# File 'lib/surrogate/hatchling.rb', line 15 def api_methods hatchery.api_methods end |
#invocations(method_name) ⇒ Object
34 35 36 |
# File 'lib/surrogate/hatchling.rb', line 34 def invocations(method_name) invoked_methods[method_name] end |
#invoke_method(method_name, args, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/surrogate/hatchling.rb', line 19 def invoke_method(method_name, args, &block) invocation = Invocation.new(args, &block) invoked_methods[method_name] << invocation if setter?(method_name) || !has_ivar?(method_name) return get_default method_name, invocation, &block end interfaces_must_match! method_name, args Value.factory(get_ivar method_name).value(method_name) end |