From: Eric Hodel Date: 2006-07-19T08:27:40+09:00 Subject: Re: How to preserve $~ when extending Regexp#match On Jul 18, 2006, at 3:13 PM, Brendan Baldwin wrote: > Because of the magical nature of the $~ global variable and its > derivatives $&,$+,$`,$',$1-9, we wind up losing it from scope with > this > extension to the Regexp class: > > /myregexp/.match("test my regexp") > $~ # <= nil > > Is anyone out there aware of any way to set $~ in the "caller's" > binding > from within Regexp#match *without* requiring a manual call_stack to be > implemented via set_trace_func? I played around with this for MetaRuby and couldn't find a way to implement it. I believe it is impossible outside of set_trace_func/ evil.rb level hackery. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com