Skip to content

Instantly share code, notes, and snippets.

@patrickarlt
Created February 15, 2011 15:11
Show Gist options
  • Save patrickarlt/827627 to your computer and use it in GitHub Desktop.
Save patrickarlt/827627 to your computer and use it in GitHub Desktop.
#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