From: David Alan Black Date: 2001-04-15T10:07:01+09:00 Subject: [ruby-talk:13672] Re: Question on gsub with a block Hello -- On Sun, 15 Apr 2001, Matt Armstrong wrote: > Second, I wanted code that replaces all strings "" with the > return value of the XXX method. Is there any better way than the > following to do this? I don't like having to repeat the regexp match to > pull out the (\S+). > > page = template.gsub(/\/) { |s| > if /\/ =~ s > send($1) > end > } You can get the submatch into the block like this (untested): page = template.gsub(//) { send($1) } David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav