开发者

How can I see the details about the object in server log?

开发者 https://www.devze.com 2023-03-10 13:50 出处:网络
I am trying to debug the user object created by writing ruby code like puts user which then开发者_如何学运维 I can check it on the server log.

I am trying to debug the user object created by writing ruby code like

puts user

which then开发者_如何学运维 I can check it on the server log.

Apparently, the server log says something like

#<User:0x3b53440>

but it does not show details about the user object. (for example, its name or email values)

How should I modify the code so that the detail information about object will be produced?

I want some function in ruby that does similar job as PHP's print_r or var_dump.


Try using the Object.inspect method:

puts user.inspect

Here's the documentation: http://www.ruby-doc.org/core/classes/Object.html#M001025


Often I'll write my own inspect or to_s method for an object, to provide me the view into the object that I want.

If Ruby can't find either of those methods for an object, it'll return the object's ID, and nothing more, because it doesn't know what else to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号