From: Lou Zell Date: 2008-08-01T05:51:04+09:00 Subject: Re: super with block Lou Zell wrote: > Mikael, I can deal with that, I'll swap out the $'s with block params. > Thanks for the workaround! > > Lou Actually, this did not work the way I expected. It is fine for a case like this: str = "match1" gsub!(/(match1)/) {|m| m} But not this: str = "match1match2" gsub!(/(match1)(match2)/) {|m1,m2| m1 + m2} Where I am really looking for: str = "match1match2" gsub!(/(match1)(match2)/) { $1 + $2} So let me ask this instead: How do I pass a block from one method to another without invoking the block? For instance, let's say I want to create a method nsub! that behaves EXACTLY like gsub! class String def nsub!(*args) gsub!(args[0]) {yield} end end This will not work, say I do this: s = String.new("whatever") s.nsub!(/(what)/) {$1} The yield in the body of nsub! invokes the block {$1}, but in this context $1 is nil, so it is like I am calling gsub!(args[0]) {nil} Which is obviously not what I want. I would like to pass the original code block: gsub!(args[0]) {$1} Any ideas? Lou -- Posted via http://www.ruby-forum.com/.