value = gets
However, if this is left as it is, a line break will occur when outputting, so use the chomp method.
value = gets.chomp
The to_i method is convenient when you want to calculate the acquired numerical value.
value = gets.to_i
to_i method can convert string to number Conversely, if you want to change a number to a string, use the
to_s
method
a b c
When the values are entered on one line separated by spaces like this, the split method
value = gets.split(" ")
You can get the values in the form of an array by using the split method You can check the contents in the same form as an array like value [0] and value [1]
value = gets.chars
a b c
When the values are entered on one line separated by spaces like thisvalue = ["a", " ", "b", " ", "c"]
Get the values as an array called
value = gets.chomp.split(" ")
By writing like this, the line feed code can also be cut off, which is convenient.
I think this is generally used
value = gets.split(" ").map(&:to_i)
When all the values are numbers, you can get them in the form of an array and convert them to numbers at the same time by writing like this.
value = readlines
redalines can get multi-line strings as a line-by-line array.
Unlike gets, typing a line break does not end keyboard input.
Please let me know if you make a mistake or have an easier way!