Created
June 3, 2017 04:25
-
-
Save brunkb/67e0c1187b658f0f3e0d4f08e8318843 to your computer and use it in GitHub Desktop.
Groovy Dynamic Method Invocation
This file contains 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 addOne( a ) { a + 1 } | |
def addTwo ( b ) { b + 2 } | |
def tellMeWhatToRun = { what, val -> | |
"$what"(val) | |
} | |
println addOne(1) | |
println addTwo(5) | |
println tellMeWhatToRun("addOne", 2) | |
println tellMeWhatToRun("addTwo", 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another way to branch without if/else