📝 Edit page
➕ Add page
Looping
Each
This is the typical Ruby way to do things.
See article - Learn how to use Ruby each
Array
One-line:
my_array = [1, 2, 3]
my_array.each { |n| puts "Number: #{n}" }
Multi-line:
my_array = [1, 2, 3]
my_array.each do |n|
text = "Number: #{n}"
puts text
end
Hash
my_hash = {min: 2, max: 5}
my_hash.each { |key, value| puts "k: #{key}, v: #{value}" }
For
This is more like Python.
my_array = [1, 2, 3]
for n in my_array do
puts "Number: #{n}"
end