Help us understand the problem. What is going on with this article?

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

自分用メモ。

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

value = readlines.map(&:chomp)

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

例)りんご バナナ

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

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

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

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

・#の場合

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

参考

https://qiita.com/Hayate_0807/items/2e9705091b181a104621

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした