Guest User

Untitled

a guest
Jul 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. #closures as I currently understand them
  2.  
  3. free_variable = 1
  4.  
  5. clos = lambda { p "I'm a closure because I hold on to #{free_variable += 1}" }
  6.  
  7. non_clos = lambda { |x| p "I'm not a closure :(, because #{x += 1} hasn't changed" }
  8.  
  9. p clos.call
  10. p clos.call
  11. p non_clos.call(free_variable)
  12. p non_clos.call(free_variable)
  13. p non_clos.call(free_variable)
  14. p clos.call
  15. p clos.call
  16. p clos.call
Add Comment
Please, Sign In to add comment