From: "Vincent L." Date: 2008-06-04T19:57:08+09:00 Subject: Re: instance_eval, regexp with block : losing $1 Vincent L. wrote: > I finally managed to get it to work : > > class Base > def self.match(name, regexp, &block) > define_method(name) do |text| > puts "#{text}" > text.gsub!(regexp) do > #hack to restore magical $~ (and so $1, $2, etc.) in block > eval('lambda{|x| $~ = x}', block).call($~) > block.call #or instance_eval(&block) instance_eval(&block) works definitely better here. -- Posted via http://www.ruby-forum.com/.