- Week 2's Theme is Ruby Blocks and Closures (Topics covered: What is block?, How to create a block?, How does a block get passed and executed?, Proc object, & operator, lambda, Where do blocks get used?, What is a closure.) and here are the references from the web site:
- Resources
- Blocks and Closures in Ruby conversation with Matz (Dec. 2003)
- Blocks can be closures article (see the end of the article) from Programming Ruby
- Code Blocks and Iteration article from devarticles.com
- Closures in Ruby example code by Paul Cantrell
- Crossing borders: Closures article by Bruce Tate
- Of closures, methods, procs, scope, and Ruby blog by Josh Staiger
- Closure from wikipedia.com
- Closures and Higher-Order Functions blog by Reginald Braithwaite (Jan. 2007)
- Explains the benefits of using closure through an example code
- Some useful closures, in Ruby article by Eric Kidd (Feb. 2007)
- Shows some design patterns where closure is used
- Here is the PDF file: Presentation (4/7/2009: Read/Printed out ~half pages)
- Exercise #1: Ruby Blocks (p.1-9)
- (1.1) RubyBlock_TwoFormats (p.2-4)
- (1.2) RubyBlock_yieldExecuteSuppliedBlock (p.4-7)
- (1.3) RubyBlock_yieldWithParameters (p.7-8)
- (1.4) RubyBlock_yieldWithParameters2 (p.8-9)
- Exercise #2: Proc object and lambda (p.9-15)
- (2.1) RubyBlock_Proc_CreateAndCall (p.9-10)
- (2.2) RubyBlock_Proc_CreateAndCall2 (p.10-11) - Had to type it in, but easy.
- (2.3) RubyBlock_Proc_AsReturnValue (p.11)
- (2.4) RubyBlock_Proc_AsArgument (p.11-12)
- (2.5) RubyBlock_lambda (p.12)
- (2.6) RubyBlock_lambda_diffFromProcNew1 (p.13-14) - Got Different Output (think ok).
- (2.7) RubyBlock_lambda_diffFromProcNew2 (p.15)
- Exercise 3: Ruby & (Ampersand) Operator (p.15-17)
- (3.1) RubyBlock_Ampersand_blockToProc (p.16)
- (3.2) RubyBlock_Ampersand_ProcToBlock (p.17)
- Exercise #4: Blocks and Iterators (p.17-19)
- (4.1) RubyBlock_Iterator (p.18)
- (4.2) RubyBlock_Iterator2 (p.18-19)
- Exercise #5: Closure Basics (p.19-
- (5.0) RubyClosure_example0 (p.20-21)
- (5.1) RubyClosure_example1 (p.21)
- (5.2) RubyClosure_example2 (p.21-22) -- Tricky ;>)
- (5.3) RubyClosure_example3 (p.22-23)
- (5.4) RubyClosure_example4 (p.23-24) -- Finished at 4:30pm.
- Lab and homework
- 5512_ruby_blocks.zip (Unzip it in a directory of your choice and read lab document from
/ruby_blocks/index.html to proceed) - Online lab document (This is the same document you will find in the hands-on lab zip file)
- Homework
- Change Log
Tuesday, April 7, 2009
Week 2: Rails Passion Course
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment