Jump to content

Execute HQ9+/Ruby: Difference between revisions

m
formatting
(add Ruby)
 
m (formatting)
Line 2:
<lang ruby>class HQ9plus
def initialize(opts={})
@program = if opts[:program] then opts[:program]
elsif opts[:filename] then File.read(opts[:filename])
else ''
Line 11:
 
def run
methodsdispatch = Hash.new(:unknown)
methodsdispatch['h'] = :hello
methodsdispatch['q'] = :quine
methodsdispatch['9'] = :beer
methodsdispatch['+'] = :accumulate
 
@program.downcase.each_char do |char|
self.send methodsdispatch[char]
end
end
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.