Module: LiveAST::ReplaceEval

Defined in:
lib/live_ast/replace_eval.rb

Class Method Summary collapse

Class Method Details

.cacheObject



30
31
32
# File 'lib/live_ast/replace_eval.rb', line 30

def cache
  Thread.current[:_live_ast_arg_cache] ||= {}
end

.module_or_instance_eval(which, remote_self, bind, args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/live_ast/replace_eval.rb', line 9

def module_or_instance_eval(which, remote_self, bind, args)
  handle_args(args)

  cache[:remote_self] = remote_self
  cache[:args] = args

  code = %{
    ::LiveAST::ReplaceEval.cache[:remote_self].
    live_ast_original_#{which}_eval %{
      ::LiveAST.eval(
        ::LiveAST::ReplaceEval.cache[:args][0],
        ::Kernel.binding,
        *::LiveAST::ReplaceEval.cache[:args][1..-1])
    }
  }

  live_ast_original_eval(code, bind)
ensure
  cache.clear
end