Ruby 检查可读性? [英] Ruby Inspect readability?
本文介绍了Ruby 检查可读性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让inspect的输出更具可读性?
Is there a way to make the output of inspect more readable?
在 Perl 中,有 Data::Dumper
使输出更易于阅读.
In Perl, there is Data::Dumper
which makes the output more easy to read.
推荐答案
ruby 标准库包含 PP(Pretty Print"的缩写),它的结构格式比标准检查要好得多:
The ruby standard library contains PP (short for "Pretty Print"), which formats structures much better than the standard inspect:
http://www.ruby-doc.org/stdlib/libdoc/pp/rdoc/index.html
您需要在源文件顶部require 'pp'
才能使用它,然后将p obj
替换为pp obj
在您的代码中.
You need to require 'pp'
at the top of your source file before you can use it, and then just replace p obj
with pp obj
in your code.
我发现它特别适用于散列和数组!
I find it really useful for hashes and arrays in particular!
这篇关于Ruby 检查可读性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文