I don’t fully understand this code… The StringIO parts. Half of it is
from the ML, and half is me trying to figure out what StringIO is (god bless
irb!!!).
Well, it works great. No namespace issues, no redirecting, and it even
catches errors!
So, now I just need some way to feed input into StringIO, I guess… so that
if did this:
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…
At Sat, 7 Dec 2002 13:05:53 +0900, Chris Pine wrote:
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…
& before input.method(f) means the Method object should be
converted to block. Or you can: