Skip to content

Instantly share code, notes, and snippets.

@ivanarrizabalaga
Created November 18, 2013 10:36
Show Gist options
  • Save ivanarrizabalaga/7525771 to your computer and use it in GitHub Desktop.
Save ivanarrizabalaga/7525771 to your computer and use it in GitHub Desktop.
Groovy snippet that adds a containsAny method to the String metaClass
//The kind of API I was looking for
String myInput="This string is FORBIDDEN"
myInput.containsAny(["FORBIDDEN","NOT_ALLOWED"]) //=>true
//Adding the method to String
String.metaClass.containsAny={notAllowedTerms->
notAllowedTerms?.inject(false,{found,term->found || delegate.contains(term)})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment