Skip to content

Instantly share code, notes, and snippets.

@egrueter-dev
Created December 24, 2014 20:56
Show Gist options
  • Save egrueter-dev/2e3091da0cfe69a02e86 to your computer and use it in GitHub Desktop.
Save egrueter-dev/2e3091da0cfe69a02e86 to your computer and use it in GitHub Desktop.
99bottles
class Song
def booze (bottle, number)
@bottle = bottle
@number = number
end
def sing
while number != 0
puts "#{number} Bottles of #{bottle} on the wall, #{number} bottles of #{bottle}, you take one down, pass it around #{number-1} bottles of #{bottle} on the wall"
number -= 1
end
end
end
99bottles = Song.new('wine', 18)
99bottles.sing
@egrueter-dev
Copy link
Author

Thanks very much for this! I've updated the code (see below)
But now i'm receiving an error:

99bottles.rb:45:in initialize': wrong number of arguments(2 for 0) (ArgumentError) from 99bottles.rb:45:innew'
from 99bottles.rb:45:in `

'

class Song
attr_accessor :bottle, :number

def sing
while
if @Number > 1
puts "#{@Number} bottles of #{@Bottle} on the wall, #{@Number} bottles of #{@Bottle}, you take one down, pass it around #{@Number-1} bottles of #{@Bottle} on the wall"
@Number -= 1
elsif @Number == 1
puts "#{@Number} bottle of #{@Bottle} on the wall, #{@Number} bottle of #{@Bottle}, you take one down, pass it around #{@Number-1} bottle of #{@Bottle} on the wall"
else
puts "We need more bottles than that!"
end
end
end
end

ninteyninebottles = Song.new('wine', 18)
ninteyninebottles.sing

@egrueter-dev
Copy link
Author

Does something change about the Song.new part of the program at the bottom?

Thanks,
Erik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment