In pickaxe book, p.371, it is said that ~ a_string is equivalent to $_ =~
a_string. Well, I tried to define MetaRuby's StringMixin#~ like that,
def ~; $_ =~ self; end
but clearly, that was way too simple. After a few hours I finally found a
way to do it. I'd like to get some advice on how to improve my code.
def ~
r,w = IO.pipe
if not fork then
set_trace_func(proc{|*a|
w.puts(Marshal.dump(eval("$_", a[4])).unpack("h*"))
w.close
exit!
})
else
Process.wait
Marshal.load([r.readline].pack("h*")) =~ self.to_str
end
end
matju