Two Tools to Make Irb Better

Here are two gems I love because they make Irb better.

Looksee: Clearly Show an Object’s Methods

In Irb when you want to show an object’s methods you might do something like this:


>> print obj.methods.sort.join("n")

But you end up with a massive list of methods that includes all methods–public, private, and protected–from the bottom-most class up the class and module chain to Object.

Enter Looksee.

>> require 'looksee'
>> lp obj

Now all of obj’s methods are shown color-formatted (to distinguish among public, private, and protected) and grouped by where they appear in the class and module hierarchy. It’s a lot easier to find what you’re looking for.

Get Looksee here.

Awesome_print: Better than Pretty_print or YAML::dump

Here’s one I just learned about today. Often in Irb you want to dump an object to the console to see its attributes. And if you just “print” it the output is hard to read. You may be familiar with pretty_print and YAML::dump as alternatives to make the dump output easier to read. Between those two I prefer YAML::dump because it outputs an attribute on each line so it’s easier to scan the list.

But awesome_print is easier still. The output is nicely indented, formatted, and colorized. When dumping an Array it includes the index number in [brackets] before each element. The index number itself isn’t so important but it shows it in white so it’s easier to find the separation between array elements.

Get Awesome_print here.