Guest User

Untitled

a guest
Jul 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. >> class Blah
  2. >> def callback(&b) @block = b; end
  3. >> def do_it; @block.call; end
  4. >> end
  5. => nil
  6. >> b = Blah.new
  7. => #<Blah:0x511580>
  8. >> n = 10
  9. => 10
  10. >> b.callback { puts n }
  11. => #<Proc:0x0050cc38@(irb):17>
  12. >> b.do_it
  13. 10
  14. => nil
  15. >> n = 5
  16. => 5
  17. >> b.do_it
  18. 5
  19. => nil
Add Comment
Please, Sign In to add comment