Ruby equivalent of Perl Data::Dumper

perl-module, ruby

Solution

Look into pp

example:

  require 'pp'
  x = { :a => [1,2,3, {:foo => bar}]}
  pp x

there is also the inspect method which also works quite nicely

  x = { :a => [1,2,3, {:foo => bar}]}
  puts x.inspect

Problem

I am learning Ruby & Perl has this very convenient module called Data::Dumper, which allows you to recursively analyze a data structure (like hash) & allow you to print it. This is very useful while debugging. Is there some thing similar for Ruby?

Original source