相当于Perl Data :: Dumper的Ruby

问题描述:

我正在学习Ruby& Perl有一个非常方便的模块,称为Data :: Dumper,它允许您递归地分析数据结构(例如哈希)和允许您打印它.这在调试时非常有用. Ruby有类似的东西吗?

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?

查看pp

示例:

  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