Skip to content

Instantly share code, notes, and snippets.

@hadrienblanc
Last active August 5, 2020 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadrienblanc/edddee307f24b11126a555b4f7e1c5e5 to your computer and use it in GitHub Desktop.
Save hadrienblanc/edddee307f24b11126a555b4f7e1c5e5 to your computer and use it in GitHub Desktop.

Fizz Buzz ruby

Objective

Write a fonction or an object of your design called FizzBuz that takes input integer n and prints all the numbers from 1 up to n in a new line.

  • if the number is divisible by 3 then print "Fizz"
  • if the number is divisible by 5 then print "Buzz"
  • if the number is divisible by both 3 and 5, print "FizzBuzz". Otherwise just print the number.

Exemple

for example FizzBuzz(15) should print as follows:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

What we expect

  • better done than perfect in a first time
  • how can we test it with rspec ?
  • in a second time how can we apply general good practices ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment