Created
March 26, 2015 21:57
-
-
Save ahirschberg/e3e7aa5782b334025d9e to your computer and use it in GitHub Desktop.
yield statements in ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def foo | |
| yield 1 | |
| yield 2 | |
| puts "* This code is inside #foo" | |
| yield 3 | |
| puts "* This code is also inside #foo" | |
| end | |
| foo # Exception: no block given (yield) (LocalJumpError) | |
| # from yield.rb:9 | |
| foo {|val| puts "> Value #{val} was passed into block"} #=> | |
| # > Value 1 was passed into block | |
| # > Value 2 was passed into block | |
| # * This code is inside #foo | |
| # > Value 3 was passed into block | |
| # * This code is also inside #foo | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment