Skip to content

Instantly share code, notes, and snippets.

@aesteve
Last active January 8, 2016 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aesteve/a245a06994edc4cdb1f6 to your computer and use it in GitHub Desktop.
Save aesteve/a245a06994edc4cdb1f6 to your computer and use it in GitHub Desktop.
FizzBuzz with meta-programming (for fun only)
Integer.metaClass.getBuzzOrFizz = {
String str= ''
if (delegate % 3 == 0) {
str += 'Fizz'
}
if (delegate % 5 == 0) {
str += 'Buzz'
}
if (!str) {
return delegate.toString()
}
str
}
// 100.times { println((it + 1).buzzOrFizz) }
1.upto(100) { println it.buzzOrFizz }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment