Created
June 27, 2018 05:46
-
-
Save micahboyd/86e6c46795a15abeab92ae9911d72c34 to your computer and use it in GitHub Desktop.
Ruby method lambda?
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
| # lambda way | |
| adder = -> (x,y) { x + y } | |
| math = -> (fn, x, y) { fn.(x,y) } | |
| math.(adder, 1, 2) # => 3 | |
| # method lambda?? | |
| adder = method def adder(x,y) | |
| x + y | |
| end | |
| math = method def math(fn, x, y) | |
| fn.(x,y) | |
| end | |
| math(adder, 1, 2) # => 3! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment