Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 红宝石漂亮印花不是';它不太漂亮_Ruby - Fatal编程技术网

Ruby 红宝石漂亮印花不是';它不太漂亮

Ruby 红宝石漂亮印花不是';它不太漂亮,ruby,Ruby,当我使用Ruby内置的Pretty Print(pp)时,结果会在一行上返回。例如,我看到的是: require 'pp' pp [1, 2, 3] # [1, 2, 3] pp({ a: 'b', c: 'd', e: 'f' }) # {:a=>"b", :c=>"d", :e=>"f"} 通过在线阅读,我的理解是它实际上应该输出如下内容: pp [1, 2, 3] # [ # 1, # 2, # 3 # ] pp({ a: 'b', c: 'd', e

当我使用Ruby内置的Pretty Print(pp)时,结果会在一行上返回。例如,我看到的是:

require 'pp'

pp [1, 2, 3]
# [1, 2, 3]

pp({ a: 'b', c: 'd', e: 'f' })
# {:a=>"b", :c=>"d", :e=>"f"}
通过在线阅读,我的理解是它实际上应该输出如下内容:

pp [1, 2, 3]
# [
#   1,
#   2,
#   3
# ]

pp({ a: 'b', c: 'd', e: 'f' })
# {
#   :a => "b",
#   :c => "d",
#   :e => "f"
# }
我遗漏了什么?

对于小数组(或散列),打印是在一行上完成的,因为(可以说)第一眼就可以理解

require 'pp'

ary = [1, 2, 3]
aaaaarrraaay = (1..100).to_a

pp ary
#> [1, 2, 3]
pp aaaaarrraaay
#> [1,
#>  2,
#>  3,
#>  4,
#>  5,
#>  ...
#>  100]
这取决于打印输出是否超过79个字符。(见附件)

但是,如果您使用
PP.PP
而不是
PP

def my_pp(anything)
    PP.pp(anything, out = $>, width = 0)
end

my_pp [1, 2, 3]
#> [1,
#>  2,
#>  3]

你有没有考虑过改用Aweasome_print?我使用了2.1.2,遇到了同样的问题,但绝妙的打印没有问题……你没有遗漏任何东西。这是一个有效的意见。但是,您的问题太琐碎,不能在这里作为问题提问。或者,如果您认为您经常看到的格式良好的输出都是
pp
输出的结果,那么您就错了。你从哪里得到这个主意的?如果您询问如何输出这些表单,您的问题可能会更有意义。