Ruby receives multi-line input

Receive multi-line input

input = readlines

#input
# 120
# 115
# 122
# 116
# 119
# 117

puts input
#Output result
# 120
# 115
# 122
# 116
# 119
# 117 

You can receive multiple lines with the readlines method

Receive multi-line input without line breaks

input = readlines.map &:chomp

#input
# 120
# 115
# 122
# 116
# 119
# 117

print input 
#Output result
# ["120", "115", "122", "116", "119", "117"]

puts input
#Output result
# 120
# 115
# 122
# 116
# 119

-Chop method: Removes line breaks in character strings. -Convert elements to integers with the map method

Recommended Posts

Ruby receives multi-line input
Ruby input / output
Ruby standard input
Ruby Learning # 10 Getting User Input
[Ruby] Receive input from console
[Rails] Get standard input for multi-line data
From terminal to Ruby (standard input / output)