<grumble>...replying to my own post...</grumble>
----- Original Message -----
Now I just need to figure out how to grab the input *as it's being grabbed*
so I can echo it to the output...
----------------------------
Nevermind. It was pretty easy:
def executeCode (code, input)
code = "begin\n" +
code +
"\nrescue Exception => error\n" +
"puts error.inspect\n" +
"end\n"
strIO = StringIO.new
if !input.empty?
input = input.join("\n")+"\n"
input = StringIO.new (input, "r")
class << strIO; self; end.class_eval do
%w[gets getc read].each do |f|
define_method(f) do
inStr = input.method(f).call
puts '<'+inStr+'>'
inStr
end
end
end
end
strIO.instance_eval code
strIO.string
end
It's just that I don't know anything about define_method or StringIO, so I
feel lost... also, I didn't know you could associate Method objects to a
method call just like Proc objects... could you always do that? It makes
sense...
Chris