Created
May 4, 2010 14:32
-
-
Save ryanbriones/389476 to your computer and use it in GitHub Desktop.
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 takes_an_optional_block(&block) | |
| block_given_for_optional = block_given? | |
| stash_block { | |
| block_given_for_stash = block_given? | |
| puts "block_given_for_optional: #{block_given_for_optional}" | |
| puts "block_given_for_stash: #{block_given_for_stash}" | |
| } | |
| end | |
| def stash_block(&block) | |
| $block = block | |
| end | |
| def call_stashed | |
| puts "block_given for call_stashed: #{block_given?}" | |
| $block.call | |
| end | |
| takes_an_optional_block { "foo" } | |
| call_stashed | |
| puts "\nround 2:" | |
| takes_an_optional_block | |
| call_stashed | |
| puts "\nround 3:" | |
| takes_an_optional_block | |
| call_stashed { "bar" } |
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
| block_given for call_stashed: false | |
| block_given_for_optional: true | |
| block_given_for_stash: true | |
| round 2: | |
| block_given for call_stashed: false | |
| block_given_for_optional: false | |
| block_given_for_stash: false | |
| round 3: | |
| block_given for call_stashed: true | |
| block_given_for_optional: false | |
| block_given_for_stash: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment