Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Created May 28, 2011 16:06
Show Gist options
  • Select an option

  • Save fumokmm/996983 to your computer and use it in GitHub Desktop.

Select an option

Save fumokmm/996983 to your computer and use it in GitHub Desktop.
Groovy's operator override Test.
class NumHolder {
int num = 0
def plus(int n) { num += n; println 'puls!'; this }
def minus(int n) { num -= n; println 'minus!'; this }
def negative() { num = -num; println 'negative!'; this }
}
def nh = new NumHolder()
assert 0 == nh.num
nh += 1
assert 1 == nh.num
nh = -nh
assert -1 == nh.num
nh -= 1
assert -2 == nh.num
@fumokmm

fumokmm commented May 28, 2011

Copy link
Copy Markdown
Author
puls! negative! minus!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment