-[Ruby] The difference between gets and gets.chomp is in the line breaks! -[Ruby] How to use gets -[paiza Development Diary](https://paiza.hatenablog.com/entry/2019/09/20/%E5%88%9D%E5%BF%83%E8%80%85%E3%81%A7% E3% 82% 82Ruby% E3% 81% A7% E3% 83% 97% E3% 83% AD% E3% 82% B0% E3% 83% A9% E3% 83% 9F% E3% 83% B3% E3% 82% B0% E5% 95% 8F% E9% A1% 8C% E3% 82% 92% E8% A7% A3% E3% 81% 91% E3% 82% 8B% E3% 82% 88% E3% 81% 86% E3% 81% AB) -How to easily pluralize English words with Rails -How to receive value from Ruby standard input
//Input value:Character string line break: Yes
input = gets
//Input value: Character string Line feed: None
input = gets.chomp
//Input value: Numerical line break: Yes
input = gets.to_i
//Input value: Numerical line break: None
input = gets.chomp.to_i
-How to receive value from Ruby standard input
//Input values are stored in an array * Numerical value
input = gets.split.map(&:to_i)
//Divide and store in array
a,b,c = gets.split(" ").map &:to_i
//Store input values in order
a = readlines.map &:to_i
//Multiple lines&&Storage of multiple elements * Character string
lines = []
while line = gets
lines << line.chomp.split(' ')
end
//Multiple lines&&Storage of multiple elements * Numerical value
lines = []
while line = gets
lines << line.chomp.split(' ').map(&:to_i)
end
//Number of repetitions
n = 5
//Array settings
sample = []
//Stored in an array for the number of repetitions
n.times do
sample.push(gets.chomp.split(" ").map &:to_i)
end
//Get input value
sample = readlines.map &:to_i
//Variable declaration
n = 5
//each method
sample.each do |i|
if n < 10
n += 1
else
puts "sample"
end
end
//Absolute value acquisition
n = 5
sample = n.abs
//Singular → plural
sample = "post".pluralize
puts sample
Recommended Posts