From: Chris Pine Date: 2002-12-07T13:05:53+09:00 Subject: Re: StringIO (was: Namespaces (was: protected program in a program)) ...replying to my own post... ----- 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