Hello --

On Sun, 15 Apr 2001, Matt Armstrong wrote:

> Second, I wanted code that replaces all strings "<!-- XXX -->" 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+\S+\s+-->/) { |s|
>       if /\<!--\s+(\S+)\s+-->/ =~ s
>         send($1)
>       end
>     }


You can get the submatch into the block like this (untested):

   page = template.gsub(/<!--\s+(\S+)\s+-->/) { send($1) }


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav