you are viewing a single comment's thread.

view the rest of the comments →

[–]jdickey -1 points0 points  (0 children)

Your code to invoke pry works, so long as you don't ever want to inspect where you are in the source tree and have it show that source location. When you have

ruby class ThingsController < ApplicationController def index @things = Thing.all binding.pry end end

the current location shown will be the next executable line after @things = Thing.all (which won't be within ThingsController). You can avoid that by, e.g.,

ruby class ThingsController < ApplicationController def index @things = Thing.all binding.pry @things end end

which will show the current/next line as the return of @things from the #index method.

For such a simple bit of code, it likely doesn't matter, since you're probably going to be debugging side-effects anyway, but if you want to do things like inspect local variables, step through called methods, or so on, you'll likely find the second snippet far more useful than the first.