Skip to content

Instantly share code, notes, and snippets.

@siriniok
Created January 14, 2018 14:54
Show Gist options
  • Save siriniok/54bcc0b433b4229282306a2f81c99b20 to your computer and use it in GitHub Desktop.
Save siriniok/54bcc0b433b4229282306a2f81c99b20 to your computer and use it in GitHub Desktop.
My Ruby Debugging Cheatsheet
# Figure out where a method was defined
object = Object.new
puts object.method(:blank?).source_location
# Opening a dependency from a project
$ bundle open active_support
# Find which method Super is Calling
def foo
puts method(:foo).super_method.source_location
super
end
# List all methods on an object
object.methods
# Un-debug a gem
$ gem pristine activesupport # $ gem pristine --all
# Print stack
puts "#" * 90
puts caller
puts "#" * 90
# or just `raise`
# Vim Shortcut
# " puts the caller
# nnoremap <leader>wtf oputs "#" * 90<c-m>puts caller<c-m>puts "#" * 90<esc>
# Print source location of method
p method(:render).source_location
# Disassemble Ruby code:
code = <<~CODE
a = 4
b = 10
puts a + b
CODE
puts RubyVM::InstructionSequence.compile(code).disasm
References:
1) http://www.schneems.com/2016/01/25/ruby-debugging-magic-cheat-sheet.html
2) https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment