module Rdbc class Contract class << self include Translating def pre(method, &block) define_method(method_pre(method), &block) end def post(method, &block) define_method(method_post(method), &block) end def invariant(&block) define_method(:invariant, &block) end end include Translating class AssertionFailed < RuntimeError end def assert(condition) raise AssertionFailed unless condition end def send_method_pre(method, object, *args) method_pre = method_pre(method) if respond_to?(method_pre) send(method_pre, object, *args) end end def send_invariant(object) if respond_to?(:invariant) invariant(object) end end def send_method_post(method, object_pre, object, exception, result, *args) method_post = method_post(method) if respond_to?(method_post) send(method_post, object_pre, object, exception, result, *args) end end end end