Skip to content

Instantly share code, notes, and snippets.

@aesteve aesteve/fizzbuzz.groovy
Last active Jan 8, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.