CSC/ECE 517 Fall 2012/ch1b 1w60 ac: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 12: Line 12:
yield
yield
</pre>
</pre>
You can also pass parameters to the yield function, like so:
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:
<pre>
<pre>
yield parameter
yield parameter

Revision as of 21:44, 29 September 2012

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

How It Works

Why It's Useful

Examples

Further Readings

References