Class: Rdbc::Decorator
- Inherits:
-
Object
- Object
- Rdbc::Decorator
- Defined in:
- lib/rdbc/decorator.rb
Instance Method Summary collapse
-
#initialize(object, contract) ⇒ Decorator
constructor
A new instance of Decorator.
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(object, contract) ⇒ Decorator
Returns a new instance of Decorator.
3 4 5 6 |
# File 'lib/rdbc/decorator.rb', line 3 def initialize(object, contract) @object = object @contract = contract end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rdbc/decorator.rb', line 8 def method_missing(method, *args) object_pre = @object.clone @contract.send_method_pre(method, @object, *args) exception = nil begin result = @object.send(method, *args) rescue => exception end @contract.send_invariant(@object) @contract.send_method_post(method, object_pre, @object, exception, result, *args) if exception.nil? result else raise exception end end |