Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there equivalent for PHP's print_r in Ruby / Rails?

Tags:

In PHP you can do:

print_r($var) or vardump($var)

which prints "human-readible" information about variable.

Is there equivalent functions / helpers for those in Ruby / Rails ?

like image 631
pirho Avatar asked Jan 29 '09 12:01

pirho


2 Answers

In Rails templates you can do

<%= debug an_object %> 

and it will do nice HTML PRE output.

like image 123
Honza Avatar answered Oct 02 '22 15:10

Honza


Try using pp. You will need to require it in scripts (or in irb if your .irbc doesn't already do this):

require 'pp' 

Then you can 'PrettyPrint' an object thus:

pp object 
like image 27
Antibaddy Avatar answered Oct 02 '22 15:10

Antibaddy