Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

@HitomiWata

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

自分用メモ。

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

value = readlines.map(&:chomp)

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

例)りんご バナナ

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

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

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

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

・#の場合

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

参考

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
0
Help us understand the problem. What are the problem?