Created
May 13, 2016 12:00
-
-
Save jdoiwork/133f5538bdc8fbaf5585f5eed84c6ac7 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
| class App | |
| def plus1(n) | |
| n + 1 | |
| end | |
| def double(n) | |
| n * 2 | |
| end | |
| def triple(n) | |
| [n, n, n] | |
| end | |
| def run(n) | |
| [ | |
| :plus1, | |
| :double, | |
| :double, | |
| :triple, | |
| ].reduce(n, &call) | |
| end | |
| def apply(x, f) | |
| method(f).(x) | |
| end | |
| def call | |
| method(:apply) | |
| end | |
| end | |
| result = App.new.run(10) | |
| p result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment