Skip to content

Instantly share code, notes, and snippets.

@oscardelben
Created July 6, 2012 15:56
Show Gist options
  • Save oscardelben/3061040 to your computer and use it in GitHub Desktop.
Save oscardelben/3061040 to your computer and use it in GitHub Desktop.
Minimal debugger written in Ruby
class Foo
def speak
'hello'
end
end
my_proc = Proc.new do |event, file, line, id, binding, classname|
printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
while cmd = gets.chomp do
if cmd == 'n'
break
elsif cmd == 'c'
set_trace_func(nil)
else
begin
p eval(cmd, binding)
rescue Exception => e
puts e.message
end
end
end
end
def debugger
set_trace_func(my_proc)
end
debugger
Foo.new.speak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment