“p"和“p"有什么区别?和“pp"? [英] What is difference between "p" and "pp"?

查看:241
本文介绍了“p"和“p"有什么区别?和“pp"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实做了一些搜索,但找不到简单问题的答案.

I did do some searching, but can't find an answer to simple question.

ppp 在 Ruby 中有什么区别?我知道你需要require 'pp'.除此之外还有什么区别?

What is difference between p and pp in Ruby? I know you need to require 'pp'. Besides that what are the differences?

推荐答案

p 用于检查变量作为调试助手.它可以打印方法 #inspect 的输出.例如 p foo 将输出 foo.inspect 的内容.

p is used to inspect a variable as a debug aide. It works printing the output of the method #inspect. For example p foo will output the content of foo.inspect.

有时您需要调试复杂变量或嵌套变量.在这种情况下,p 将输出难以理解的长行.相反,pp 将尝试排列变量的内容,以便更容易理解,例如缩进嵌套数组或为复杂对象的每个实例变量使用一行.pp 调用 #pretty_inspect 方法(pp 库将 #pretty_inspect 方法添加到许多类中,例如 #pretty_inspectcode>String、ArrayStruct).

Sometimes you need to debug complex variables or nested variables. In this case p will output a long line that is hard to understand. Instead, pp will put try to arrange the content of the variable so that it is easier to understand, for example indenting nested arrays or using one line for each instance variable of a complex object. pp does this calling the #pretty_inspect method (the pp library adds #pretty_inspect methods to many classes such as String, Array or Struct).

要记住:p = 打印,pp = 漂亮的打印.

To remember: p = print, pp = pretty print.

这篇关于“p"和“p"有什么区别?和“pp"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆