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