Yield and Passing Blocks
Explore the yield keyword and how to pass blocks to methods dynamically.
1
Yield and Passing Blocks
Ruby allows passing blocks to methods using the yield keyword.
In this lesson, you will learn how to use yield to execute a block inside a method.

2
Using Yield
The yield keyword runs the block given to the method.
def greet
puts 'Before yield'
yield
puts 'After yield'
end
greet { puts 'Hello from the block!' }All lessons in this course
- Defining Methods
- Blocks, Procs, and Lambdas
- Yield and Passing Blocks