From: Mike Gold Date: 2008-12-11T08:18:35+09:00 Subject: lambda with $1 fails as gsub block 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.lang.ruby/browse_thread/thread/e24a19e6ea75e5de/0211d0b304cbbad0?hl=en%C3%93d0b304cbbad0 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? -- Posted via http://www.ruby-forum.com/.