...

/

Block Arguments

Block Arguments

This lesson discusses what block arguments are, their usage and their Ruby syntax.

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

Let’s have a look at some examples with arrays.

In our previous example that used the method times our block did not accept an argument. A block that accepts an argument looks like this:

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

And, again, this is the same ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy