module Pact::DSL
Ripped from blog.joecorcoran.co.uk/2013/09/04/simple-pattern-ruby-dsl and then fixed up by using www.skorks.com/2013/03/a-closure-is-not-always-a-closure-in-ruby/ to access variables and methods defined in the calling scope.
Public Instance Methods
build(*args, &block)
click to toggle source
# File lib/pact/shared/dsl.rb, line 61 def build(*args, &block) new_instance_of_delegation_target_class = self.new(*args) dsl_delegator_class = self.const_get('DSL_DELEGATOR_CLASS') dsl_delegator = dsl_delegator_class.new(new_instance_of_delegation_target_class) dsl_delegator.instance_eval_with_previous_context_available(&block) if block new_instance_of_delegation_target_class.finalize new_instance_of_delegation_target_class end
dsl(&block)
click to toggle source
# File lib/pact/shared/dsl.rb, line 70 def dsl(&block) dsl_delegator_class = Class.new(DslDelegator, &block) self.const_set('DSL_DELEGATOR_CLASS', dsl_delegator_class) end