Class: Compact::ArgumentInterceptor
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Compact::ArgumentInterceptor
- Defined in:
- lib/compact/argument_interceptor.rb
Instance Attribute Summary collapse
-
#invocations ⇒ Object
Returns the value of attribute invocations.
Instance Method Summary collapse
-
#initialize(delegate) ⇒ ArgumentInterceptor
constructor
A new instance of ArgumentInterceptor.
- #method_missing(method, *args, &block) ⇒ Object
- #register(contract) ⇒ Object
Constructor Details
#initialize(delegate) ⇒ ArgumentInterceptor
Returns a new instance of ArgumentInterceptor.
5 6 7 8 9 |
# File 'lib/compact/argument_interceptor.rb', line 5 def initialize(delegate) @invocations = [] @contract = nil super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/compact/argument_interceptor.rb', line 15 def method_missing(method, *args, &block) returns = super invocation = Invocation.new(method: method, args: args, returns: returns) @invocations.push(invocation) @contract.add_invocation(invocation) if @contract returns end |
Instance Attribute Details
#invocations ⇒ Object
Returns the value of attribute invocations.
3 4 5 |
# File 'lib/compact/argument_interceptor.rb', line 3 def invocations @invocations end |
Instance Method Details
#register(contract) ⇒ Object
11 12 13 |
# File 'lib/compact/argument_interceptor.rb', line 11 def register(contract) @contract = contract end |