Sha256: 3ba7393f42aef86e22d76f30d06e5c358c766443da0c7083bb861deaf18290b2
Contents?: true
Size: 811 Bytes
Versions: 1
Compression:
Stored size: 811 Bytes
Contents
class FizzBuzz # Returns an array solving the classic 1 to 100 FizzBuzz problem. def crunch(start=1, stop=100) return nil unless start < stop return_values = Array.new (start..stop).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 class Fixnum # For testing the Fizz-, Buzz-, or Fizzbuzz-ness of a Fixnum # 3.fizz? # => true # 5.buzz? # => nil # 15.fizzbuzz? # => true def fizz? return true if (self % 3) == 0 end def buzz? return true if (self % 5) == 0 end def fizzbuzz? return true if (self % 15) == 0 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fizz-buzz-0.3.0 | lib/fizz-buzz.rb |