From: Gregory Brown Date: 2008-08-01T06:03:41+09:00 Subject: Re: super with block On Thu, Jul 31, 2008 at 4:51 PM, Lou Zell wrote: > Which is obviously not what I want. I would like to pass the original > code block: > > gsub!(args[0]) {$1} > > > Any ideas? If you don't mind a little redundancy, you can match the string first, pull the MatchData object, and yield that: >> class String >> def nsub!(*args) >> m = match(args[0]) >> gsub!(args[0]) { yield(m) } >> end >> end => nil >> str = "match1match2" => "match1match2" >> str.nsub!(/(match1)(match2)/) { |m| m[1] + "---" + m[2] } => "match1---match2" >> str => "match1---match2" It would be nice if MatchData was yielded by gsub instead of a string. -greg -- Killer Ruby PDF Generation named after a magnificent sea creature: http://github.com/sandal/prawn | Non-tech stuff at: http://metametta.blogspot.com