Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "tracer"
require "tracer/irb"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
33 changes: 29 additions & 4 deletions lib/tracer/irb.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative "../tracer"
require "irb/cmd/nop"
require "irb"

Expand Down Expand Up @@ -46,6 +47,11 @@ class Trace < TraceCommand
description "Trace the target object (or self) in the given expression. Usage: `trace [target,] <expression>`"

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
Expand All @@ -56,8 +62,13 @@ def execute(*args)
target = eval(args.first, irb_context.workspace.binding)
expression = args.last
else
raise ArgumentError,
"wrong number of arguments (given #{args.size}, expected 1..2)"
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
Expand All @@ -69,7 +80,14 @@ class TraceCall < TraceCommand
category "Tracing"
description "Trace method calls in the given expression. Usage: `trace_call <expression>`"

def execute(expression)
def execute(*args)
expression = args.first

unless expression
puts "Please provide the expression to trace. Usage: `trace_call <expression>`"
return
end

b = irb_context.workspace.binding
Tracer.trace_call { eval(expression, b) }
end
Expand All @@ -79,7 +97,14 @@ class TraceException < TraceCommand
category "Tracing"
description "Trace exceptions in the given expression. Usage: `trace_exception <expression>`"

def execute(expression)
def execute(*args)
expression = args.first

unless expression
puts "Please provide the expression to trace. Usage: `trace_exception <expression>`"
return
end

b = irb_context.workspace.binding
Tracer.trace_exception { eval(expression, b) }
end
Expand Down