Module: FizzBuzzer::V12a
- Defined in:
- lib/fizzbuzzer.rb
Instance Method Summary collapse
Instance Method Details
#fizzbuzz ⇒ Object
326 327 328 329 |
# File 'lib/fizzbuzzer.rb', line 326 def fizzbuzz fizzbuzz_engine( 1..100, [["Fizz", -> n { n % 3 == 0 }], ["Buzz", -> n { n % 5 == 0 }]]) end |
#fizzbuzz_engine(range, factors) ⇒ Object
316 317 318 319 320 321 322 323 324 |
# File 'lib/fizzbuzzer.rb', line 316 def fizzbuzz_engine(range, factors) range.map do |n| result = "" factors.each do |(name, predicate)| result << name if predicate.call(n) end result == "" ? n : result end end |