Skip to content

Instantly share code, notes, and snippets.

@rhysyngsun
Created August 20, 2009 00:48
Show Gist options
  • Save rhysyngsun/170746 to your computer and use it in GitHub Desktop.
Save rhysyngsun/170746 to your computer and use it in GitHub Desktop.
// Example #1
def splitMe = 'First sentence. Second.'
def cl = { split('.') }
cl.resolveStrategy = Closure.DELEGATE_FIRST
cl.delegate = splitMe
def sentences = cl()
// Example #2 (shorthand for #1)
def splitMe = 'First sentence. Second.'
def cl = { split('.') }
def sentences = splitMe.with(cl)
// Example #3 (the infamous it)
def splitMe = 'First sentence. Second.'
def cl = { it.split('.') }
def sentences = cl.call(splitMe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment