使用Rails 4.0.4
和Ruby 2.1.1
,并在模型的控制器内部,我想使用pp
签出一个对象。我打电话给debugger
暂停执行并环顾四周。但是,pp
似乎正在截断事物的输出并且不允许它们出现在多行上:
>pp ShopOrder
#<Shoporder id: 64, order_id: "142949823232-3232353652342", shop_id: 1, order_
status: "Completed", order_tests_queued: "2014-04-02 18:19:36", shipped_time:
nil, shipping_address_name: "John Doe", total: 43.9, created_time: "2014-04-02
03:04:20", raw: "{\"order_id\":\"142949823232-3232353652342\",\"order_sta...">
( ^^ I did not truncated this for the question, it just ends this way ^^ )
我习惯pp
通常很好地格式化它并在多行上显示它,更类似于使用y ShopOrder
获取格式良好的to_yaml
输出时发生的事情:
--- !ruby/object:Shoporder
attributes:
id: 64
order_id: 142949823232-3232353652342
shop_id: 1
order_status: Completed
order_tests_queued: 2014-04-02 18:19:36.498044000 Z
shipped_time:
shipping_address_name: John Doe
total: 43.9
created_time: 2014-04-02 03:04:20.000000000 Z
... (output continues correctly but has been truncated for this example )
当irb_context.echo
返回true
y
和to_yaml
很好但有时我也希望能够使用pp
为什么这不按预期工作?
答案 0 :(得分:0)
如果内存服务pp
依赖于pretty_print
方法输出。也许某些东西在你的模型中定义,或者覆盖它并截断super
返回的字符串。
答案 1 :(得分:0)
这是(奇怪的)大型物体的预期行为。
请勿pp
使用pretty_print
使用来自ap
的{{1}}