Skip to content

Instantly share code, notes, and snippets.

@hgmiguel
Created July 25, 2014 19:32
Show Gist options
  • Select an option

  • Save hgmiguel/ada233bd9c55ac812108 to your computer and use it in GitHub Desktop.

Select an option

Save hgmiguel/ada233bd9c55ac812108 to your computer and use it in GitHub Desktop.
groovy method missing pattern
def dynamicMethods = [
[regex:"hasPermission(.*)", method:this.&hasPermission],
[regex:"create(.*)Permission", method:this.&createPermission]]
def methodMissing(String name, args) {
def method = dynamicMethods.find { name =~ it.regex}
if(method) {
def match = name =~ method.regex
return method.method(match[0][1], * args)
} else
throw new MissingMethodException(name, PermissionService , args)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment