相当于Perl Data :: Dumper的Ruby [英] Ruby equivalent of Perl Data::Dumper
本文介绍了相当于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
这篇关于相当于Perl Data :: Dumper的Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文