Execute HQ9+/Ruby: Difference between revisions
Content added Content deleted
(add Ruby) |
m (formatting) |
||
Line 2: | Line 2: | ||
<lang ruby>class HQ9plus |
<lang ruby>class HQ9plus |
||
def initialize(opts={}) |
def initialize(opts={}) |
||
@program = if opts[:program] then opts[:program] |
@program = if opts[:program] then opts[:program] |
||
elsif opts[:filename] then File.read(opts[:filename]) |
elsif opts[:filename] then File.read(opts[:filename]) |
||
else '' |
else '' |
||
Line 11: | Line 11: | ||
def run |
def run |
||
dispatch = Hash.new(:unknown) |
|||
dispatch['h'] = :hello |
|||
dispatch['q'] = :quine |
|||
dispatch['9'] = :beer |
|||
dispatch['+'] = :accumulate |
|||
@program.downcase.each_char do |char| |
@program.downcase.each_char do |char| |
||
send |
self.send dispatch[char] |
||
end |
end |
||
end |
end |