4 ms·
Ruby blocks, procs, and lambdas
- hmsimha 13y agoThis is an extremely useful post! Thanks for sharing it! I think it deserved more attention on HN.
- awaxman11 13y agoThanks! It got a bunch of upvotes right away and made it to the homepage but then got flagged for the early traction :(
- yebyen 13y agoAwesome! I was looking for this article about 12 months ago. Still just as useful to know today as it was then. For anyone who doesn't already know this inside and out, the tl;dr spoiler: the surprises are that procs do not even care how many arguments they are passed, and that they can return on behalf of the function in which they are executed. Compared to lambdas, which spew runtime errors if they don't get the right number of arguments passed in, and which always return control to the line after where they were executed, regardless of whether the return keyword is used. I'm reminded of the Dave Thomas pipelines using fibers series of articles. I'll just leave this here: http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipelines-using.html http://pragdave.blogs.pragprog.com/pragdave/2007/12/pipeline... http://pragdave.blogs.pragprog.com/pragdave/2008/01/pipelines-using.html http://pragdave.blogs.pragprog.com/pragdave/2008/01/pipeline...