为什么Ruby的IRB print_print没有正确?

时间:2014-04-03 17:39:13

标签: ruby-on-rails ruby pretty-print irb

使用Rails 4.0.4Ruby 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

时启用回声

yto_yaml很好但有时我也希望能够使用pp

为什么这不按预期工作?

2 个答案:

答案 0 :(得分:0)

如果内存服务pp依赖于pretty_print方法输出。也许某些东西在你的模型中定义,或者覆盖它并截断super返回的字符串。

答案 1 :(得分:0)

改为使用Awesome Print

这是(奇怪的)大型物体的预期行为。

请勿pp使用pretty_print使用来自ap的{​​{1}}