34 lines
513 B
Ruby
34 lines
513 B
Ruby
class Program
|
|
def initialize
|
|
@instructions = []
|
|
(2 + rand(4)).times do
|
|
@instructions << random_instruction
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def random_instruction
|
|
case rand(2)
|
|
when 0
|
|
[:load, (65 + rand(26)).chr]
|
|
when 1
|
|
[:output]
|
|
end
|
|
end
|
|
|
|
def to_s
|
|
@instructions.map do |instruction, *params|
|
|
case instruction
|
|
when :load
|
|
"load #{params.first.inspect}"
|
|
when :output
|
|
"output"
|
|
end
|
|
end.join("\n")
|
|
end
|
|
|
|
def execute
|
|
end
|
|
end
|