5

When stepping through the Ruby Debugger in Rails, how do I only have it stop only at code that I wrote, skipping over all the native Rails code?

(ie skipping all the code that looks like this)

/Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/core_ext/module/remove_method.rb:4
remove_method(method)
(rdb:1) s
[76, 85] in /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/core_ext/class/attribute.rb
   76          def self.#{name}?() !!#{name} end
   77  
   78          def self.#{name}=(val)
   79            singleton_class.class_eval do
   80              remove_possible_method(:#{name})
=> 81              define_method(:#{name}) { val }
   82            end
   83  
   84            if singleton_class?
   85              class_eval do
/Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/core_ext/class/attribute.rb:81
define_method(:#{name}) { val }
(rdb:1) s
[79, 88] in /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/core_ext/class/attribute.rb
   79            singleton_class.class_eval do
   80              remove_possible_method(:#{name})
   81              define_method(:#{name}) { val }
   82            end
   83  
=> 84            if singleton_class?
   85              class_eval do
   86                remove_possible_method(:#{name})
   87                def #{name}
   88                  defined?(@#{name}) ? @#{name} : singleton_class.#{name}

Thanks!

Jonathan Leung
  • 2,051
  • 2
  • 19
  • 24

3 Answers3

1

I think what your looking for is something like this if I understand your question right. You'll want to step over rather than step into, that way if your using a method for rails you don't go into the rails code. I hope this helps and good luck.

Donavan White
  • 1,126
  • 10
  • 23
  • This is definitely helpful but I don't see anything in there that will allow me to skip all the native rails code except if I put a breakpoint at the beginning of all the code that I write and this is certainly not ideal... – Jonathan Leung Mar 29 '12 at 17:47
1

If you occasionally stepped in some Rails code, just press c in a console. This will move you to the next breakpoint you have set (or return to the same one if you're inside a loop) or will simply end page request if there's no breakpoints left.

Nash Bridges
  • 2,350
  • 14
  • 19
  • This is what I do now, but say if you want to follow the train of code from a controller going into model code (say upon saving an object or something). You will have to put a breakpoint in your controller code and also in your model code. Is there a way, if you didn't know where the code led to (ie you didn't know that the controller code led to the model code), it would just stop in the model code, skipping all the native rails code? Ie a "continue until it hits code that I wrote and then breakpoint there." – Jonathan Leung Mar 29 '12 at 17:50
  • @JonathanLeung Sorry, ruby-debug can't distinguish where "native" code begins and where it ends :) It would be very non-trivial code to solve such problem. If you haven't said to ruby-debug "I want to stop here, here and here", it will go through all method chain until the end. – Nash Bridges Mar 29 '12 at 18:38
  • 1
    @NashBridges It actually could be achieved by enabling the user to add a folder to a skipped files list, for example, `~/rvm/gems/ruby.2.0.0-p247/gems`. It doesn't seem that difficult and I agree it would be useful. – deivid Aug 26 '13 at 22:05
0

There are 3 major debugging commands

  • c - Continue
  • s - Step into
  • n - next/ Step over

What you're looking for is "n", it allows you to go through a list of methods without going into the code or ruby gem that contains the rest of the code.

Ryan Taylor
  • 12,559
  • 2
  • 39
  • 34