[RUBY] [Rails] Get standard input for multi-line data

Personal notes.

Store multiple lines of data in an array with standard input

value = readlines.map(&:chomp)

If there are multiple data in one row with standard input, store them in an array

Example) Apple banana

line = gets.split
p line
["Apple","banana"]

Output multiple data stored in an array to one line

There is a space between data, you can specify a specific symbol etc. ・ If blank

puts array.join(' ')
Apple banana

·#in the case of

puts array.join('#')
Apple#banana

reference

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

Recommended Posts

[Rails] Get standard input for multi-line data
Initial data input with [Rails] seed_fu!
[Rails] Manage data for each seed file
[Swift] Template for receiving standard input of Paiza
[Java] How to get and output standard input
Ruby standard input
Rails / Ruby: How to get HTML text for Mail
Create an EC site with Rails5 ⑥ ~ seed data input ~
Rails6: Input the initial data of ActionText using seed
Ruby receives multi-line input
[Rails] Prepare dummy data to be used for testing [Faker]
[Rails] Implemented a pull-down search function for Active Hash data