From: Charles Oliver Nutter Date: 2008-06-04T23:13:32+09:00 Subject: Re: instance_eval, regexp with block : losing $1 Vincent L. wrote: > class Foo < Base > match :g, /(.)g$/i do > puts "$1 in passed block : #{$1}" #Unfortunately $1 is lost ! > 'ggg' #so only hardcoded values :-( > end > end ... > But I don't manage to get these to work... > I need to get $1, $2, etc. special values > in the block I pass in Base subclasses. > How can I do that ? The backref and numbered group globals are tied to the containing method/class body. So here, where you have a match call with a block inside a class body, the capture would be the one that lives in that body. That's part of the problem with relying on these special variables and the side effect of e.g. gsub: you can't implement the same behavior in Ruby because certain core methods like gsub have "special" side effects impossible to emulate. - Charlie