Skip to content

Instantly share code, notes, and snippets.

@jamesgary
Created May 2, 2013 18:51
Show Gist options
  • Save jamesgary/5504424 to your computer and use it in GitHub Desktop.
Save jamesgary/5504424 to your computer and use it in GitHub Desktop.
Dissecting Ruby with Ruby - Richard Schneeman (@schneems) - RailsConf2013

Dissecting Ruby with Ruby

Richard Schneeman (@schneems)

  • Get into a library
    • bundle open wicked
    • Make sure you've set your $EDITOR
  • Forget fancy debuggers
    • All you need is puts
    • A rubyist's tracer round: puts "================="
  • Notation
    • ClassOrModule#instance_method
    • ClassOrModule.class_method
  • Problem: Where is this method being called?
    • Kernel#caller gives you the backtrace
    • puts caller.inspect
  • Problem: Where is this method defined?
    • Object#method returns a Method
    • Method#source_location returns file and line number
    • User.last.method(:github_url).source_location
    • Great for when you grep for a method and see it defined in a bunch of place
  • If you see super and want to see what it'll do...
    • You can use self.class.ancestors to see where it'll get called
      • But that can return a crapload of ancestors
    • User.instance_method(:github_url).source_location same as above, but for an instance method
self.class.ancestors.each do |klass|
  next unless klass.method_defined?(:method_we_are_looking_for)
  puts klass.instance_method(:method_we_are_looking_for).source_location
end
  • Keep following the source by applying these tools
  • For developing OSS:
    • Open an issue
    • Reproduce the bug
    • Attempt a fix
    • At least raise awareness
  • Find the right prbolem, and the solution becomes obvious(ish)
  • Other fun tools:
    • Object#methods
    • Module#instance_methods
  • Slides are here!!!
  • Go from bug reporter to bug fixer!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment