Created
August 25, 2010 22:38
-
-
Save jimweirich/550441 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
# What's the output of this program? | |
# Compare Ruby 1.8 to 1.9. | |
def fl; lambda { return 1 }.call; 2; end | |
def fp; proc { return 1 }.call; 2; end | |
def fPn; Proc.new { return 1 }.call; 2; end | |
puts fl | |
puts fp | |
puts fPn | |
# Advanced considersions | |
def make_lambda(&block) lambda(&block) end | |
def make_proc(&block) block end | |
def fml; make_lambda { return 1 }.call; 2; end | |
def fmp; make_proc { return 1 }.call; 2; end | |
puts fml | |
puts fmp |
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
# Ruby 1.9 addition to the return scope issue. | |
def fsp; ->() { return 1; }.call; 2; end | |
puts fsp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary ... Here's the take away from this exercise:
Behaviors:
Function Behavior:
Block Behavior:
Classification
Things with Function Behavior
Things with Block Behavior