B
Brendan Baldwin
Consider the following Regexp/MatchData extension, which pops a copy of
the original Regexp into the MatchData object resulting from
Regexp#match. Forget for a minute *why* anyone might want to do this:
class Regexp
alias_method
riginal_match, :match
def match(str)
m=self.original_match(str)
m.regexp=self unless m.nil?
m
end
end
class MatchData
attr_accessor :regexp
end
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?
Thanks!
--Brendan Baldwin :: (e-mail address removed)
the original Regexp into the MatchData object resulting from
Regexp#match. Forget for a minute *why* anyone might want to do this:
class Regexp
alias_method
def match(str)
m=self.original_match(str)
m.regexp=self unless m.nil?
m
end
end
class MatchData
attr_accessor :regexp
end
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?
Thanks!
--Brendan Baldwin :: (e-mail address removed)