Iterators are hugely important in idiomatic Ruby code. .each, .map, and .select let you work with items in an array or hash in a way that's readable and clear.
ruby
prices = [100, 250, 400]
prices.each do |price|
puts "Price: #{price} yen"
end
tax_included = prices.map do |price|
price * 1.1
end
puts tax_includedeach runs a block once for every item. map transforms each item and returns a brand-new array.
You should see
Price: 100 yen Price: 250 yen Price: 400 yen 110.00000000000001 275.0 440.00000000000006Info
A handy rule of thumb: reach for map when you want new data back, and each when you just want to produce output.