p vs 放入 Ruby [英] p vs puts in Ruby

查看:43
本文介绍了p vs 放入 Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby 中的 pputs 有什么区别吗?

Is there any difference between p and puts in Ruby?

推荐答案

p foo 打印 foo.inspect 后跟换行符,即打印 inspect 而不是 to_s,它更适合调试(因为你可以例如区分 1, "1"> 和 "2\b1",在没有 inspect 的情况下打印时你不能这样做.

p foo prints foo.inspect followed by a newline, i.e. it prints the value of inspect instead of to_s, which is more suitable for debugging (because you can e.g. tell the difference between 1, "1" and "2\b1", which you can't when printing without inspect).

这篇关于p vs 放入 Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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