Module: LiveAST::ReplaceEval

Defined in:
lib/live_ast/replace_eval.rb

Class Method Summary collapse

Class Method Details

.cacheObject



28
29
30
# File 'lib/live_ast/replace_eval.rb', line 28

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

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



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

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