From: Gregory Brown Date: 2008-08-01T06:08:39+09:00 Subject: Re: super with block On Thu, Jul 31, 2008 at 4:51 PM, Lou Zell wrote: > 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? I forgot to answer this before: >> class String >> def nsub!(*args,&block) >> gsub!(args[0],&block) >> end >> end But unfortunately, this does not fix your problem: >> str = "match1match2" => "match1match2" >> str.nsub!(/(match1)(match2)/) { |m| $1 + "---" + $2 } NoMethodError: undefined method `+' for nil:NilClass