[Ruby ~ Iterative processing ~] Study memo 4

Ruby review. It's almost my study memo. Please do not excessive expectations.

Iterative processing

--each method

By using each method, the elements of the array can be extracted in order and processed. The usage is "array.each do |Variable name|, And write the process you want to execute before "end".

How to write


Array.each do |Variable name|
  #processing
end

Each method iterates as many times as there are elements in the array. 「| |The elements of the array are entered into the variables enclosed in "" one by one, and the processing in each method is executed on that. The variable name in each method can be any name you like, but it is customary to use the singular form of the variable name in the array.

Example of use


colors = ["red", "Blue", "yellow"]
colors.each do |color|
  puts "color: #{color}"
end

Output result


color: 赤color
color: 青color
color: 黄color

Recommended Posts

[Ruby ~ Iterative processing ~] Study memo 4
[Ruby] Iterative processing
Ruby Iterative Processing
[Java ~ Conditional branching / Iterative processing ~] Study memo (3)
Ruby study memo (recursive function)
Iterative processing
Ruby memo
Ruby Study Memo (Test Driven Development)
Memorandum (Ruby: Basic grammar: Iterative processing)
[Beginner] Various iterative processing for Ruby arrays
[wip] Ruby memo
java iterative processing
Ruby conditional branch processing
ruby basic syntax memo
Ruby study notes (puts)
Dot installation study memo 01
[Java ~ Array ~] Study memo 4
Play Framework Study Memo Database ①
Java Silver Study Method Memo
[Self-use memo] (Ruby) class, class instance, instance
Personal memo Progate Ruby I (2)
Introduction to JUnit (study memo)
Ruby About various iterative processes
Java study memo 2 with Progate
Personal memo Progate Ruby I (1)
Ruby study notes (variables & functions)
ruby exercise memo I (puts)
Play Framework Study Memo Database ②Read
ruby exercise memo VI (hello class)
spring framework Simple study memo (2): AOP
[Swift] "for-in statement" about iterative processing
Memorandum (other conditional bifurcation, iterative processing)
[Study session memo] Java Day Tokyo 2017
Introduction to Ruby processing system self-made
Ruby on Rails 6.0 environment construction memo
String output method memo in Ruby
[Note] [Beginner] Ruby writing memo (refactoring) 1
[Java] Processing time measurement method memo
[Ruby / Refactoring] From Ruby iterative processing like Java and C language to Ruby-like iterative processing
[Ruby] Explanation for beginners of iterative processing with subscripts such as each_with_index!
Iterative processing of Ruby using each method (find the sum from 1 to 10)
How to insert processing with any number of elements in iterative processing in Ruby