CSC/ECE 517 Fall 2012/ch1b 1w60 ac
SaaS - 3.8 yield()
Introduction (Preface)
Code Blocks & Closures
The Map & Grep Functions
The yield() Function
What Is It?
Simply put, the yield function in Ruby allows the execution of a code block. The code block used by the yield function can be passed as a parameter to the function using yield, or it can be declared elsewhere.
Syntax
In it's most basic form, the yield function can be called with simply:
yield
In this form, the yield function will simply execute the code block passed to the function it's called from. You can also pass parameters to the yield function, like so:
yield parameter