lib/chanko/invoker.rb in chanko-2.0.6 vs lib/chanko/invoker.rb in chanko-2.0.7

- old
+ new

@@ -38,32 +38,20 @@ else super end end - def __current_run_default_depth - @__run_default_depth ||= 0 - end - - def __increment_run_default_depth - @__run_default_depth = __current_run_default_depth + 1 - end - - def __decrement_run_default_depth - @__run_default_depth = __current_run_default_depth - 1 - end - def __find_unit_local(method_name) __current_unit_locals.has_key?(method_name) end def __fetch_unit_local(method_name) __current_unit_locals[method_name] end def __current_unit_locals - __unit_locals_stack[-1 - __current_run_default_depth] || {} + __unit_locals_stack.last || {} end def __unit_locals_stack @__unit_locals_stack ||= [] end @@ -83,28 +71,29 @@ def __defaults_stack @__defaults_stack ||= [] end def __default_block - __defaults_stack[-1 - __current_run_default_depth] + __defaults_stack.last end def __has_default_block? !!__default_block end def __invoke_default_block current_default_block = __default_block begin - __increment_run_default_depth - if view? - capture(&current_default_block) - else - instance_exec(&current_default_block) + __without_default_stack do + __without_locals_stack do + if view? + capture(&current_default_block) + else + instance_exec(&current_default_block) + end + end end - ensure - __decrement_run_default_depth end end def __with_default_stack(default) __defaults_stack << default @@ -116,8 +105,22 @@ def __with_unit_locals_stack(locals) __unit_locals_stack << locals yield ensure __unit_locals_stack.pop + end + + def __without_default_stack + default = __defaults_stack.pop + yield + ensure + __defaults_stack << default + end + + def __without_locals_stack + locals = __unit_locals_stack.pop + yield + ensure + __unit_locals_stack << locals end end end