module Rdbc class Decorator def initialize(object, contract) @object = object @contract = contract end 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 end end