Ruby 相当于 Perl Data::Dumper
我正在学习 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 pp
示例:
还有一个 inform 方法,它也工作得很好
Look into pp
example:
there is also the inspect method which also works quite nicely
如果我需要快速检查某些内容,我通常会使用 YAML 转储。
在
irb
中,语法很简单y obj_to_inspect
。在普通的 Ruby 应用程序中,您可能需要向文件添加require 'YAML'
,但不确定。以下是 irb 中的示例:
最终的=> nil 只是意味着该方法没有返回任何内容。它与你的数据结构无关。
I normally use a YAML dump if I need to quickly check something.
In
irb
the syntax is simplyy obj_to_inspect
. In a normal Ruby app, you may need to add arequire 'YAML'
to the file, not sure.Here is an example in
irb
:The final
=> nil
just means the method didn't return anything. It has nothing to do with your data structure.您可以使用Marshal,marshal,YAML
you can use Marshal, amarshal, YAML