Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (64 sloc) 1.25 KB
require 'rubygems' # Ruby 1.8用
require 'pebbles/sl'
class HQ9Plus
def initialize(src)
@src = src
@count = 0
end
def run
@src.each_char do |c|
case c
when "H"
hello
when "S"
run_sl
when "Q"
print_source
when "9"
print_99_bottles_of_beer
when "+"
increment
end
end
end
private
def hello
puts "Hello, world!"
end
def run_sl
Pebbles::SL.run
end
def print_source
print @src
end
def print_99_bottles_of_beer
99.downto(0) do |k|
case k
when 0
before = "no more bottles"
after = "99 bottles"
when 1
before = "1 bottle"
after = "no more bottles"
when 2
before = "2 bottles"
after = "1 bottle"
else
before = "#{k} bottles"
after = "#{k-1} bottles"
end
if k == 0
action = "Go to the store and buy some more"
else
action = "Take one down and pass it around"
end
puts "#{before.capitalize} of beer on the wall, #{before} of beer."
puts "#{action}, #{after} of beer on the wall."
puts "" unless k == 0
end
end
def increment
@count += 1
end
end
HQ9Plus.new(ARGF.read).run