Sha256: e47e73b60ee23c812b68dfb60c40461ab435ec2c1321ab0396d16de84983fa94

Contents?: true

Size: 762 Bytes

Versions: 1

Compression:

Stored size: 762 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
  #   3.buzz?       #  => false
  #   15.fizzbuzz?  #  => true

  def fizz?
    self % 3 == 0
  end

  def buzz?
    self % 5 == 0
  end

  def fizzbuzz?
    self % 15 == 0
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fizz-buzz-0.3.1 lib/fizz-buzz.rb