Advertisement
Guest User

Untitled

a guest
Jan 18th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.39 KB | None | 0 0
  1. Code:
  2.  
  3.  
  4. def foo
  5.   retval = yield
  6.   puts "Value returned by the block: #{retval}."
  7. end
  8.  
  9. def bar
  10.   puts "I'm method bar. I'm going to call method foo with a block."
  11.   foo do
  12.     puts "I'm a block."
  13.     break "Batman"
  14.     puts "Code after the break statement inside the block."
  15.   end
  16. end
  17.  
  18. bar
  19.  
  20.  
  21.  
  22. Output:
  23.  
  24. I'm method bar. I'm going to call method foo with a block.
  25. I'm a block.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement