Skip to content

Instantly share code, notes, and snippets.

@namuan
Created August 27, 2013 10:31
Show Gist options
  • Save namuan/6351958 to your computer and use it in GitHub Desktop.
Save namuan/6351958 to your computer and use it in GitHub Desktop.
Replace switch-case/if-else block with maps
def sum(a, b) {
println "sum"
a + b
}
def sub(a, b) {
println "sub"
a - b
}
def d = [
'sum': this.&sum,
'sub': this.&sub
]
println d['sum'](10, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment