Skip to content

Instantly share code, notes, and snippets.

@bdkosher
Created January 7, 2017 02:19
Show Gist options
  • Save bdkosher/887cd5d9a8d9a323ed235387e91347ee to your computer and use it in GitHub Desktop.
Save bdkosher/887cd5d9a8d9a323ed235387e91347ee to your computer and use it in GitHub Desktop.
Should be part of Groovy JDK
[Integer, Long, BigInteger].each { clazz ->
clazz.metaClass.isOdd = { -> delegate % 2 == 1}
clazz.metaClass.isEven = { -> !delegate.isOdd()}
}
(1..10).each { n -> println "$n is odd? ${n.isOdd()}. $n is even? ${n.isEven()}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment