{{ message }}

Instantly share code, notes, and snippets.

# psparrow/bottles.rb

Last active Feb 18, 2017
My solution to Sandi Metz and Katrina Owen's 99 Bottles of OOP problem
 class Bottles def song verses 99, 0 end def verses high, low high.downto(low).map { |count| verse count }.join "\n" end def verse count bottles = Hash.new { |hash, key| "#{key} bottles" } bottles[6] = '1 six-pack' bottles[1] = '1 bottle' bottles[0] = 'no more bottles' actions = Hash.new 'Take one down and pass it around' actions[1] = 'Take it down and pass it around' actions[0] = 'Go to the store and buy some more' remaining = count > 0 ? count - 1 : 99 <<-VERSE #{bottles[count].capitalize} of beer on the wall, #{bottles[count]} of beer. #{actions[count]}, #{bottles[remaining]} of beer on the wall. VERSE end end

### psparrow commented Feb 18, 2017

 Replacing "6 bottles" with "1 six-pack" only requires adding a single line of code... bottles[6] = '1 six-pack'

### psparrow commented Feb 18, 2017

 Updating this with a minimal refactoring and the addition of the six-pack feature.