Archive for May 1st, 2008

php’s print_r equivalent in ruby on rails

I was going through my google analytics logs today and I noticed that a lot of folks were coming to my site on Google searches for stuff like ‘print_r + ruby on rails‘.

So I figured I’d write a blog post about it, because I’ve had the same problem.

What you’re looking for is ‘inspect’.

If you have an array, hash or object that you want to take a quick-and-dirty look at just type in

objectname.inspect

and you’ll get an output of the contents of said array, hash or object.

Here is a screen capture of a quick irb session to show you how it works.

print_r equivalent in ruby on rails

I hope this helps.

Add comment May 1st, 2008


Calendar

May 2008
S M T W T F S
« Apr   Jun »
 123
45678910
11121314151617
18192021222324
25262728293031

Posts by Month

Posts by Category