更新时间:2023-11-25 17:00:58
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!