From: Brian Candler Date: 2008-12-11T17:50:47+09:00 Subject: Re: lambda with $1 fails as gsub block Mike Gold wrote: > 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. Here's a solution: def meth(replace) ">x".gsub(%r!(\W)x!) { |match| replace[$~] } end replace = lambda { |match| puts "match is #{match.inspect}" puts "match[1] is #{match[1].inspect}" } meth(replace) # => match[1] is ">" -- Posted via http://www.ruby-forum.com/.