Created
January 31, 2013 19:19
-
-
Save SoldierCoder/4685583 to your computer and use it in GitHub Desktop.
I went a little crazy and through lambdas in the mix
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
def create_a_line(n) | |
b = f = "" | |
print_number = true | |
fizz_or_buzz = lambda {|n, mod_by| (n%mod_by==0) ? true : false } | |
if fizz_or_buzz.call n, 5 | |
b="Buzz" | |
print_number = false | |
end | |
if fizz_or_buzz.call n, 3 | |
f="Fizz" | |
print_number = false | |
end | |
print_string = ((print_number==true) ? "#{n}" : "#{f}#{b}") | |
return print_string | |
end | |
universe = 1..100 | |
universe.each do |n| | |
a_line = create_a_line (n) | |
puts "#{a_line}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment