Class: IRB::ExtendCommand::Trace

Inherits:
TraceCommand show all
Defined in:
lib/tracer/irb.rb

Instance Method Summary collapse

Methods inherited from TraceCommand

transform_args

Instance Method Details

#execute(*args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/tracer/irb.rb', line 57

def execute(*args)
  if args.empty?
    puts "Please provide the expression to trace. Usage: `trace [target,] <expression>`"
    return
  end

  args = args.first.split(/,/, 2)

  case args.size
  when 1
    target = irb_context.workspace.main
    expression = args.first
  when 2
    target = eval(args.first, irb_context.workspace.binding)
    expression = args.last
  else
    puts "Please provide the expression to trace. Usage: `trace [target,] <expression>`"
    return
  end

  unless expression
    puts "Please provide the expression to trace. Usage: `trace [target,] <expression>`"
    return
  end

  b = irb_context.workspace.binding
  Tracer.trace(target) { eval(expression, b) }
end