【发布时间】:2014-05-15 17:14:36
【问题描述】:
使用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
为什么没有按预期工作?
【问题讨论】:
标签: ruby-on-rails ruby pretty-print irb