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

.handle_args(args) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/live_ast/replace_eval.rb', line 32

def handle_args(args)
  if args.empty?
    raise ArgumentError, "block not supplied"
  end
  
  args[0] = Common.arg_to_str(args[0])
  
  unless (1..3).include? args.size
    raise ArgumentError,
    "wrong number of arguments: instance_eval(src) or instance_eval{..}"
  end
  
  args[1] = Common.arg_to_str(args[1]) if args[1]
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