Last active
January 8, 2016 10:42
-
-
Save aesteve/a245a06994edc4cdb1f6 to your computer and use it in GitHub Desktop.
FizzBuzz with meta-programming (for fun only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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