Advertisement
vedranvinko

closure-like constructs

Mar 29th, 2012
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.63 KB | None | 0 0
  1. # So in fact, there are no less than seven -- count 'em, SEVEN -- different closure-like constructs in Ruby:
  2. #
  3. #      1. block (implicitly passed, called with yield)
  4. #      2. block (&b  =>  f(&b)  =>  yield)  
  5. #      3. block (&b  =>  b.call)    
  6. #      4. Proc.new  
  7. #      5. proc  
  8. #      6. lambda    
  9. #      7. method
  10. #
  11. # Though they all look different, some of these are secretly identical, as we'll see shortly.
  12. #
  13. # We already know that (1) and (2) are not really closures -- and they are, in fact, exactly the same thing.
  14. # Numbers 3-7 all seem to be identical. Are they just different syntaxes for identical semantics?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement