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.
のようなRubyの配列があり["dog", "cat", bat"]ます。のように、スペースで区切られた単語で単一の文字列に結合するにはどうすればよい"dog cat bat"ですか? 要素を繰り返し処理して 1 つずつ結合するのは簡単ですが、1 行で行う方法はありますか?
["dog", "cat", bat"]
"dog cat bat"
a = ["dog", "cat", "bat"] a.join(" ") #=> "dog cat bat"
かわいいショートカット:
["dog", "cat", "bat"] * ' ' #=> "dog cat bat"
[「犬」、「猫」、「コウモリ」].join ' '