Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Inspect readability?

Tags:

ruby

Is there a way to make the output of inspect more readable?

In Perl, there is Data::Dumper which makes the output more easy to read.

like image 903
Carmen Avatar asked Jun 28 '11 04:06

Carmen


1 Answers

The ruby standard library contains PP (short for "Pretty Print"), which formats structures much better than the standard inspect:

http://www.ruby-doc.org/stdlib/libdoc/pp/rdoc/index.html

You need to require 'pp' at the top of your source file before you can use it, and then just replace p obj with pp obj in your code.

I find it really useful for hashes and arrays in particular!

like image 196
Paul Prestidge Avatar answered Sep 21 '22 04:09

Paul Prestidge