Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
puts a1.zip(a2)和 和有什么不一样a1.zip(a2)?为什么输出以不同的方式出现?
puts a1.zip(a2)
a1.zip(a2)
a1 = %w{a b c} a2 = %w{1 2 3} a1.zip(a2) # => [["a", "1"], ["b", "2"], ["c", "3"]] puts a1.zip(a2) # => # a # 1 # b # 2 # c # 3 #=> nil
你在做puts一个,只是在另一个做zip电话。为什么你期望它们是一样的?
puts
zip
puts确实在自己的行中打印数组的每个元素,这就是您在此处看到的。IRB 默认用于inspect打印对象。虽然您看到的不同,但zip两种情况下方法的输出是相同的。
inspect