Module: LiveAST::Evaler

Extended by:
Common
Defined in:
lib/live_ast/evaler.rb

Class Method Summary collapse

Methods included from Common

arg_to_str, arg_to_str2, check_arity, check_is_binding, location_for_eval

Class Method Details

.eval(parser_source, *args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/live_ast/evaler.rb', line 8

def eval(parser_source, *args)
  evaler_source, bind, *rest = handle_args(*args)

  file, line = location_for_eval(bind, *rest)
  file = LiveAST.strip_token(file)

  key, = Linker.new_cache_synced(parser_source, file, line, false)

  begin
    NATIVE_EVAL.call(evaler_source, bind, key, line)
  rescue Exception => e
    e.backtrace.map! { |s| LiveAST.strip_token s }
    raise e
  end
end

.handle_args(*args) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/live_ast/evaler.rb', line 24

def handle_args(*args)
  args.tap do
    check_arity(args, 2..4)
    args[0] = arg_to_str(args[0])
    check_is_binding(args[1])
    args[2] = arg_to_str(args[2]) if args[2]
  end
end