Recall & Review
beginner
What are block parameters in Ruby?
Block parameters are variables that a block receives when it is called. They allow the block to accept input values and use them inside the block.
Click to reveal answer
beginner
How do you define block parameters in Ruby?
Block parameters are defined between vertical bars | | right after the block keyword or do. For example:
array.each { |item| puts item } where item is the block parameter.Click to reveal answer
beginner
What happens if you don't specify block parameters in a Ruby block?
If you don't specify block parameters, the block will not receive any input values from the method calling it. You won't be able to access the values passed to the block.
Click to reveal answer
intermediate
Can a Ruby block have multiple parameters? How?
Yes, a Ruby block can have multiple parameters separated by commas inside the vertical bars. For example:
array.each_with_index { |item, index| puts "#{index}: #{item}" } where item and index are block parameters.Click to reveal answer
intermediate
What is the difference between block parameters and method parameters in Ruby?
Block parameters are variables passed to a block, which is a chunk of code passed to a method. Method parameters are variables passed to the method itself. Blocks are called inside methods and can receive their own parameters separately.
Click to reveal answer
How do you write block parameters in Ruby?
✗ Incorrect
Block parameters are always written inside vertical bars | | right after the block keyword or do.
What will this code print? <br>
[1, 2, 3].each { |n| puts n * 2 }✗ Incorrect
The block parameter n takes each element, multiplies by 2, and prints it.
What happens if you omit block parameters but the block expects them?
✗ Incorrect
If no block parameters are specified, the block ignores any values passed to it.
Which of these is a valid block parameter list?
✗ Incorrect
Block parameters are always inside vertical bars | | separated by commas.
Can a block parameter be named the same as a method parameter?
✗ Incorrect
Block parameters and method parameters have separate scopes, so they can have the same name without conflict.
Explain what block parameters are and how you use them in Ruby.
Think about how a block receives values from a method like each.
You got /3 concepts.
Describe the difference between method parameters and block parameters in Ruby.
Consider how methods and blocks receive their inputs separately.
You got /4 concepts.