LoginSignup
21
18

More than 5 years have passed since last update.

【Ruby】配列の要素を半角スペース区切りで出力する

Last updated at Posted at 2016-05-01

条件

  • 配列の要素を半角スペース区切りで出力する
  • 末尾の要素は半角スペースでなく改行で出力する

1次元配列の場合

array = ["red", "blue", "white"]
puts array.join(' ')

多次元配列の場合

array = ["red", ["blue", "gold", ["green", "pink"]], ["white", "brown"]]
puts array.join(' ')

Rubyは1次元配列でも多次元配列でも同様に書けるので素敵。

関連

【PHP】配列の要素を半角スペース区切りで出力する

21
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
18