Gray's Matter
Justice Gray - North America's favorite metrosexual software consultant

I Wish These People Updated More Than Once a Year

Now that Mrs. L days are over, we continue our largely silent screencast series with an explanation of "the block", which you would've seen at the tail end of the previous screencast.  A couple of supplemental notes:

the ! operator (as seen in the collect! method call) indicates that the method we are calling is destructive - whichever object calls the method will have its contents altered.  This is a de facto standard in Ruby - if you define an object that has a destructive method, said method should have a ! at the end.  Non-destructive methods return a copy of the object and thus do not have the !.

yield, when seen in a method, calls whatever anonymous method was passed as an argument.  This screencast shows it both a simple example and also how to define your own each method on a class.

Finally, the lambda operator takes a block as an argument and creates a Proc object out of that block; this has the effect of preserving any context of the block, as we'll see!

Download part 3 here!

Wednesday, October 11, 2006 #