Sha256: 0e6b18765224355adcc21e54728e437f1e797b7413c2f347f9b8f648bd269578
Contents?: true
Size: 860 Bytes
Versions: 1
Compression:
Stored size: 860 Bytes
Contents
module FizzBuzz def fizzbuzz return_values = Array.new self.each do |n| if n.fizzbuzz? return_values << "FizzBuzz" elsif n.buzz? return_values << "Buzz" elsif n.fizz? return_values << "Fizz" else return_values << n end end return return_values end end module FizzBuzzNumerics # For testing the Fizz-, Buzz-, or Fizzbuzz-ness of a Fixnum # 3.fizz? # => true # 3.buzz? # => false # 15.fizzbuzz? # => true # # Note that using these methods, fizzbuzzy numbers like 15 will fizz, buzz, AND fizzbuzz. def fizz? self % 3 == 0 end def buzz? self % 5 == 0 end def fizzbuzz? self % 15 == 0 end end class Range include FizzBuzz end class Array include FizzBuzz end class Numeric include FizzBuzzNumerics end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fizz-buzz-0.5.0 | lib/fizz-buzz.rb |