LoginSignup
0
0

More than 3 years have passed since last update.

[Rails]複数行データの標準入力の取得する

Last updated at Posted at 2020-09-16

自分用メモ。

標準入力で複数行のデータを配列に格納

value = readlines.map(&:chomp)

標準入力で1行に複数データある場合、配列に格納

例)りんご バナナ

line = gets.split
p line
["りんご","バナナ"]

配列に格納されている複数データを1行に出力

データとデータの間は空白あり、特定の記号など指定できる
・空白の場合

puts array.join(' ')
りんご バナナ

・#の場合

puts array.join('#')
りんご#バナナ

参考

0
0
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
0
0