From 677fa5599c613c35ad2000becfa3605b8c35b62b Mon Sep 17 00:00:00 2001 From: ofuji0602 Date: Fri, 22 Dec 2023 16:54:25 +0900 Subject: [PATCH 1/2] Add output GitHub --- lib/fizzbuzz.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/fizzbuzz.rb b/lib/fizzbuzz.rb index 4746a88..dc149cc 100644 --- a/lib/fizzbuzz.rb +++ b/lib/fizzbuzz.rb @@ -6,6 +6,8 @@ def calculate number 'fizz' elsif number % 5 == 0 'buzz' + elsif number.to_s.include? '7' + 'GitHub' else number end From 120e66a9dbd2d45899422efd378b10860c01f776 Mon Sep 17 00:00:00 2001 From: ofuji0602 Date: Fri, 22 Dec 2023 17:13:19 +0900 Subject: [PATCH 2/2] Fix output GitHub --- lib/fizzbuzz.rb | 6 +++--- spec/fizzbuzz_spec.rb | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/fizzbuzz.rb b/lib/fizzbuzz.rb index dc149cc..f9a304d 100644 --- a/lib/fizzbuzz.rb +++ b/lib/fizzbuzz.rb @@ -1,13 +1,13 @@ class Fizzbuzz def calculate number - if number % 3 == 0 && number % 5 == 0 + if number.to_s.include? '7' + 'GitHub' + elsif number % 3 == 0 && number % 5 == 0 'fizzbuzz' elsif number % 3 == 0 'fizz' elsif number % 5 == 0 'buzz' - elsif number.to_s.include? '7' - 'GitHub' else number end diff --git a/spec/fizzbuzz_spec.rb b/spec/fizzbuzz_spec.rb index 93a63e6..bb8e9ca 100644 --- a/spec/fizzbuzz_spec.rb +++ b/spec/fizzbuzz_spec.rb @@ -20,4 +20,10 @@ it { subject.calculate(15).should eq 'fizzbuzz' } it { subject.calculate(30).should eq 'fizzbuzz' } end + context 'GitHub number' do + it { subject.calculate(17).should eq 'GitHub' } + it { subject.calculate(27).should eq 'GitHub' } + it { subject.calculate(75).should eq 'GitHub' } + it { subject.calculate(77).should eq 'GitHub' } + end end