Hacker News new | ask | show | jobs
by roboben 935 days ago
Doing the same with pry ALL THE TIME. It basically became my standard programming workflow. Especially you can also do `ls` to inspect objects and classes.

Is there any other language which can do that? And I don’t mean unergonomic debuggers.

2 comments

Another wonderful helper in Pry is `show-method`. If you type in `show-method Foo.bar`, it will pull up the source code for that method, or class, or whatever you pass to it. Great for looking something up when you don't understand what's going on behind the scenes, especially since it works on code from gems as well.
This is such an amazing pry feature that I never see people use, excellent time saver
I also sometimes use it to then open the gem source code and insert a `binding.pry` to debug but that's... uh... not something I'd really endorse.
I’ve been there too, just don’t forget to remove it! Also would never tell anyone else to do this, unless I trust them not to come to me about “everything getting all weird”
Another pro-tip in this vein is `object.methods` to see a list of the methods to which the object you're messing with will respond. I use this all of the time when I'm diving into something trying to figure out what's going on.
I always do object.methods.sort, otherwise my brain can't consume it
I use `my_object.methods.sort - Object.methods` to help reduce the methods I need to consider.
Subtracting Object.new.methods will remove more of the standard methods than Object.methods.
Even better, thank you!
Pry appears largely inspired by Smalltalk, which Ruby itself also draws heavily on, and which if anything can go much further.