Created
February 15, 2011 15:11
-
-
Save patrickarlt/827627 to your computer and use it in GitHub Desktop.
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
#This method defines a set of rules and a syntax | |
#to add then then checks all of the rules | |
def fizzbuzz(num, rules) | |
output_str="" | |
rules.each do |hash| | |
if num.remainder(hash[:number]).zero? | |
output_str << hash[:inserted_text] | |
end | |
end | |
if output_str == "" | |
output_str = num.to_s | |
end | |
puts output_str | |
end | |
rules = [ | |
{:number => 3, :inserted_text => "Fizz"}, | |
{:number => 5, :inserted_text => "Buzz"}, | |
{:number => 7, :inserted_text => "Kezz"} | |
] | |
(1..100).each do |num| | |
fizzbuzz(num, rules) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment