...

/

Block Arguments

Block Arguments

Learn how blocks can accept arguments.

Blocks make a lot of sense when passed to methods that are defined on collections like arrays and hashes.

Let’s look at some examples with arrays.

In our previous example that used the times method, our block didn’t accept an argument. A block that accepts an argument looks like this:

Press + to interact
Ruby
[1, 2, 3, 4, 5].each do |number|
puts "#{number} was passed to the block"
end
...