[RAILS] [Ruby] I tried to summarize the methods that frequently appear in paiza

References

-[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 method

//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

Array method

-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

times method + array

//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

each method + array

//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

Other

//Absolute value acquisition
n = 5
sample = n.abs


//Singular → plural
sample = "post".pluralize
puts sample

Recommended Posts

[Ruby] I tried to summarize the methods that frequently appear in paiza
[Ruby] I tried to summarize the methods that frequently appear in paiza ②
I tried to summarize the methods used
I tried to summarize the words that I often see in docker-compose.yml
I tried to summarize the basic grammar of Ruby briefly
I tried to summarize the Stream API
[Ruby] Tonight, I tried to summarize the loop processing [times, break ...]
I tried to summarize the methods of Java String and StringBuilder
I tried to organize the session in Rails
[Introduction to Java] I tried to summarize the knowledge that I think is essential
I tried to solve the tribonacci sequence problem in Ruby, with recursion.
I tried to make full use of the CPU core in Ruby
I want to get the value in Ruby
I tried to solve the tribonatch sequence problem in Ruby (time limit 10 minutes)
I tried to organize the cases used in programming
I tried to summarize the state transition of docker
I tried to implement the Euclidean algorithm in Java
I tried to summarize the basics of kotlin and java
What I did in the version upgrade from Ruby 2.5.2 to 2.7.1
I tried to summarize object orientation in my own way.
I tried to summarize iOS 14 support
I tried to explain the method
I tried to summarize Java learning (1)
I tried to summarize Java 8 now
I tried to solve the problem of "multi-stage selection" with Ruby
I tried to summarize what was asked at the site-java edition-
I tried to illuminate the Christmas tree in a life game
I tried to sort the data in descending order, ascending order / Rails
I tried to write code like a type declaration in Ruby
Special Lecture on Multi-Scale Simulation: I tried to summarize the 5th
Special Lecture on Multi-Scale Simulation: I tried to summarize the 8th
I tried to make Numeron which is not good in Ruby
I tried to solve the paiza campaign problem "Challenge from Kaito 813"
I want to change the value of Attribute in Selenium of Ruby
Special Lecture on Multi-Scale Simulation: I tried to summarize the 7th
I tried a calendar problem in Ruby
[Ruby basics] Methods that frequently use blocks
I tried to summarize Java lambda expressions
I tried the AutoValue library in Intellij
What is Docker? I tried to summarize
I tried to build Ruby 3.0.0 from source
I tried to make a parent class of a value object in Ruby
I tried to summarize the stumbling points when developing an Android application
I tried to summarize the key points of gRPC design and development
[Ruby] I tried to diet the if statement code with the ternary operator
I tried to solve the past 10 questions that should be solved after registering with AtCoder in Java
I tried to summarize about JVM / garbage collection
I tried to easily put CentOS-7 in a PC that I no longer need
I tried to implement polymorphic related in Nogizaka.
Ruby: I tried to find out where Nokogiri goes to see the encoding himself
I want to use arrow notation in Ruby
How to resolve errors that occur in the "Ruby on Rails" integration test
I tried to implement deep learning in Java
[Must see !!!] I tried to summarize object orientation!
I tried to get the distance from the address string to the nearest station with ruby
[Ruby basics] I tried to learn modules (Chapter 1)
[JavaScript] The strongest case when I tried to summarize the parts I do not understand
I tried to set tomcat to run the Servlet.
I tried to build Micra mackerel in 1 hour!
I tried to create Alexa skill in Java
How to build the simplest blockchain in Ruby