[ruby] How to receive values from standard input?


I didn't know how to get more than one input, and I found out that I was looking into it, so I'll record it. This time, it is the case where multiple elements are entered in one line.

Main subject

The following input results are converted to integer type and output.

Standard input
1999 2000
input_line = gets.split(' ').map(&:to_i)
puts input_line
Output result
[1999, 2000]

"Split" splits an element and stores it in an array.

"Map" evaluates inside the block and replaces it with an array. In this case, it means that it is replaced with an integer type.

If you make a mistake, please point it out.

Recommended Posts

[ruby] How to receive values from standard input?
From terminal to Ruby (standard input / output)
[Ruby] Summary of how to get values from standard input [Paiza skill check measures]
Learning Ruby with AtCoder 11 How to receive frequently used standard input
[Ruby] Receive input from console
Ruby standard input
Java: How to send values from Servlet to Servlet
[Ruby] How to convert from lowercase to uppercase and from uppercase to lowercase
[Java] How to receive numerical data separated by spaces in standard input
From Java to Ruby !!
[Ruby] How to use standard output in conditional branching
How to output standard from an array with forEach
How to use Ruby return
Ruby: How to use cookies
[Ruby] How to write blocks
How to migrate from JUnit4 to JUnit5
How to push from Tarminal to GitHub
How to iterate infinitely in Ruby
Ruby standard input and various methods
How to install ruby through rbenv
How to install Bootstrap in Ruby
[Ruby] How to use any? Method
Introduction to Ruby (from other languages)
How to use Ruby inject method
How to execute Ruby irb (interactive ruby)
How to change from HTML to Haml
How to display 0 on the left side of the standard input value
How to read a file and treat it as standard input
How to get and add data from Firebase Firestore in Ruby
How to get date data in Ruby
[Ruby on Rails] How to use CarrierWave
[Rails] How to convert from erb to haml
[Ruby] From the basics to the inject method
[IOS] How to get data from DynamoDB
How to call Swift 5.3 code from Objective-C
Ruby length, size, count How to use
[Flutter] How to use C / C ++ from Dart?
[Ruby] How to use slice for beginners
How to call custom or standard services from Liferay 7 / DXP-Workflow / Workflow Script
[Ruby on Rails] How to use redirect_to
[Easy] How to upgrade Ruby and bundler
[Ruby on Rails] How to use kaminari
[Struts] How to pass values between jsps
Ruby: CSV :: How to use Table Note
How to start a subscript from an arbitrary number in Ruby iterative processing
Sample to create PDF from Excel with Ruby
How to find the cause of the Ruby error
[Ruby on Rails] How to display error messages
How to link Rails6 Vue (from environment construction)
How to save to multiple tables with one input
How to add / remove Ruby on Rails columns
How to get a heapdump from a Docker container
How to dump from database (DB) to seeds file
[Ruby] How to use gsub method and sub method
How to get Class from Element in Java
[Java] How to switch from open jdk to oracle jdk
How to display the result of form input
How to get SIMD optimization from HotSpot JavaVM
[Ruby] How to generate a random alphabet string
[Ruby on Rails] How to install Bootstrap in Rails
How to build the simplest blockchain in Ruby