Skip to content

Instantly share code, notes, and snippets.

@ryoasai
Created June 22, 2011 14:43
Show Gist options
  • Save ryoasai/1040238 to your computer and use it in GitHub Desktop.
Save ryoasai/1040238 to your computer and use it in GitHub Desktop.
Adding destructive String operation.
String.metaClass.destructiveReverse << {
def chars = delegate.value;
chars.eachWithIndex {e, i ->
chars[- i - 1] = e
}
}
def s = 'groovy'
s.destructiveReverse()
assert s == 'yvoorg'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment