Module: LiveAST::Evaler

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

Class Method Summary collapse

Methods included from Common

arg_to_str, check_arity, check_is_binding, location_for_eval

Class Method Details

.eval(parser_source, *args) ⇒ Object



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

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 => ex
    ex.backtrace.map! { |s| LiveAST.strip_token s }
    raise ex
  end
end

.handle_args(*args) ⇒ Object



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

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