Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I jump into the Rails (or other Ruby libraries) source for understanding quite often. This is good advice, but for folks coming from static languages it's really a challenge to figure out how to find stuff. I've resorted to running it all under a debugger and setting breakpoints, just so I can find out which monkey-patch (or non-namespaced, duplicate class) is being called.


2 things in particular I use:

* Bundle comes with a `bundle open <gemname>` command that opens up the gems source code in whatever your shells $EDITOR is set to. I use this at least three or four times a day.

* Pry (an IRB alternative) will tell you the file + line of the definition of the method you'd be running if you ran `show-source some_object.some_method`. You can also `ls` and `cd` your way around ruby modules/objects which has been invaluable.


If you use Pry's `edit-method some_object.some_method`[1] you can actually open the method in an editor and it'll even fast forward the cursor to the first line of the method.

[1] https://github.com/pry/pry/wiki/Editor-integration#wiki-Edit...


Definitely check out Pry (http://pry.github.com). It's designed specifically for your use case... Just start Pry, load the gems you want, and then navigate to the method/class you want to know about using Pry's `ls` and `cd` commands. Once you find what you want, either use `show-source` to view the source directly in Pry, or use `edit-method` to open it in an editor.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: