M
Mike Gold
I came across this problem:
def meth(replace)
">x".gsub(%r!(\W)x!, &replace)
end
replace = lambda { |match|
puts "$1 is #{$1.inspect}"
}
">x".gsub(%r!(\W)x!, &replace) # => $1 is ">"
"" =~ %r!! # reset $1
meth(replace) # => $1 is nil
Apparently $1 is bound in a peculiar way:
http://groups.google.com/group/comp...6ea75e5de/0211d0b304cbbad0?hl=enÓd0b304cbbad0
Matz suggested that the MatchData could have been passed to the block
for convenience, however it looks more like a necessity, as I don't see
a solution short of rewriting gsub.
This suggests that for 1.9, MatchData should be passed as an optional
second argument to the block. Yes?
def meth(replace)
">x".gsub(%r!(\W)x!, &replace)
end
replace = lambda { |match|
puts "$1 is #{$1.inspect}"
}
">x".gsub(%r!(\W)x!, &replace) # => $1 is ">"
"" =~ %r!! # reset $1
meth(replace) # => $1 is nil
Apparently $1 is bound in a peculiar way:
http://groups.google.com/group/comp...6ea75e5de/0211d0b304cbbad0?hl=enÓd0b304cbbad0
Matz suggested that the MatchData could have been passed to the block
for convenience, however it looks more like a necessity, as I don't see
a solution short of rewriting gsub.
This suggests that for 1.9, MatchData should be passed as an optional
second argument to the block. Yes?