Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code:
- def foo
- retval = yield
- puts "Value returned by the block: #{retval}."
- end
- def bar
- puts "I'm method bar. I'm going to call method foo with a block."
- foo do
- puts "I'm a block."
- break "Batman"
- puts "Code after the break statement inside the block."
- end
- end
- bar
- Output:
- I'm method bar. I'm going to call method foo with a block.
- I'm a block.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement