Ruby review. It's almost my study memo. Please do not excessive expectations.
--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