Back to home

Ruby Fizzbuzz

    This requires the gem installation of minitest.

    Test file

    Create file fizz_buzz_test.rb:

    begin gem 'minitest', '>= 5.0.0' require 'minitest/autorun' require_relative 'fizz_buzz' rescue Gem::LoadError => e puts "\nMissing Dependency:\n#{e.backtrace.first} #{e.message}" puts 'Minitest 5.0 gem must be installed for the Ruby track.' rescue LoadError => e puts "\nError:\n#{e.backtrace.first} #{e.message}" puts exit 1 end # Common test data version: 1.1.0 be3ae66 class FizzBuzzTest < Minitest::Test def test_fizz # skip assert_equal "Fizz", end def test_buzz # skip assert_equal "Buzz", end def test_fizzbuzz # skip assert_equal "FizzBuzz", end def test_return_int # skip assert_equal 2, end end __END__


    Create file fizz_buzz.rb:

    class FizzBuzz def case true when arg % 3 == 0 && arg % 5 == 0 return "FizzBuzz" when arg % 3 == 0 return "Fizz" when arg % 5 == 0 return "Buzz" else return arg end end end


    Change into directory and run ruby fizz_buzz_test.rb.

    Personal image

    Dennis O'Keeffe

    • Melbourne, Australia

    Hi, I am a professional Software Engineer. Formerly of Culture Amp, UsabilityHub, Present Company and NightGuru.
    I am currently working on Visibuild.


    Get fresh posts + news direct to your inbox.

    No spam. We only send you relevant content.

    Ruby Fizzbuzz


    Share this post