Module: FizzBuzzer::V5

Defined in:
lib/fizzbuzzer.rb

Constant Summary collapse

FIZZ =
'Fizz'
BUZZ =
'Buzz'

Instance Method Summary collapse

Instance Method Details

#divisible_by?(numerator, denominator) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/fizzbuzzer.rb', line 137

def divisible_by?(numerator, denominator)
  numerator % denominator == 0
end

#divisible_by_3?(numerator) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/fizzbuzzer.rb', line 141

def divisible_by_3?( numerator )
  divisible_by?( numerator, 3 )
end

#divisible_by_5?(numerator) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/fizzbuzzer.rb', line 145

def divisible_by_5?( numerator )
  divisible_by?( numerator, 5 )
end

#fizzbuzzObject



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/fizzbuzzer.rb', line 149

def fizzbuzz
  (1..100).map do |n|
     fizz = divisible_by_3? n
     buzz = divisible_by_5? n
     case
     when fizz && buzz then FIZZ + BUZZ
     when fizz then FIZZ
     when buzz then BUZZ
     else n
     end
  end
end