Skip to content

Instantly share code, notes, and snippets.

@brunkb
Created June 3, 2017 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunkb/67e0c1187b658f0f3e0d4f08e8318843 to your computer and use it in GitHub Desktop.
Save brunkb/67e0c1187b658f0f3e0d4f08e8318843 to your computer and use it in GitHub Desktop.
Groovy Dynamic Method Invocation
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)
@brunkb
Copy link
Author

brunkb commented Jun 3, 2017

Another way to branch without if/else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment