Class: FizzBuzz

Inherits:
Object
  • Object
show all
Defined in:
lib/fizz-buzz.rb

Instance Method Summary collapse

Instance Method Details

#crunch(start = 1, stop = 100) ⇒ Object

Returns an array solving the classic 1 to 100 FizzBuzz problem.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fizz-buzz.rb', line 4

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