Module: DSLCompanion::ContextHelper
- Defined in:
- lib/dsl_companion/helpers/context_helper.rb
Instance Method Summary collapse
Instance Method Details
#execute_within_context(context = @context, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/dsl_companion/helpers/context_helper.rb', line 5 def execute_within_context(context=@context, &block) # Execute the block if any if block_given? last_saved_context = @context @context = context begin # puts ">>>> Switching to context: #{@context} (from #{last_saved_context})" @context.send :instance_variable_set, '@interpreter', @interpreter @context.instance_eval(&block) ensure @context = last_saved_context # puts "<<<< Back to context: #{@context}" end end end |