Guest User

Untitled

a guest
May 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #I can't say much about the subtle differences. However, I can point out that Ruby #1.9 now allows optional parameters for lambdas and blocks.
  2.  
  3. #Here's the new syntax for the stabby lambdas under 1.9:
  4.  
  5. stabby = ->(msg='inside the stabby lambda') { puts msg }
  6.  
  7. #Ruby 1.8 didn't have that syntax. Neither did the conventional way of declaring #blocks/lambdas support optional args:
  8.  
  9. # under 1.8
  10. l = lambda { |msg = 'inside the stabby lambda'| puts msg }
  11. #SyntaxError: compile error
  12. #(irb):1: syntax error, unexpected '=', expecting tCOLON2 or '[' or '.'
  13.  
  14. #Ruby 1.9, however, supports optional arguments even with the old syntax:
  15.  
  16. l = lambda { |msg = 'inside the regular lambda'| puts msg }
  17. #=> #<Proc:0x0e5dbc@(irb):1 (lambda)>
  18. l.call
  19. #=> inside the regular lambda
  20. l.call('jeez')
  21. #=> jeez
Add Comment
Please, Sign In to add comment