Dirk Einecke wrote:

> Hi.
>
> Marcin Miel?y?ski wrote:
>
>> It should work for any tag
>
>
> But I do not unterstand this:
>
> gsub!( /<(.+)>(.*?)<\/\1>/ ) { "<#{$1}>foo</#{$1}>" }
>
> How this code take the var "tagName" ?
>
> greetings
> Dirk Einecke
>
having #{anyvariable} inside of a double quoted string will put the 
value of anyvariable into the string.  So you can do something along the 
lines of

tagName = "BODY"
and then anywhere in your regular expression where you want to use the 
value of tagName you put "#{tagName}"

This is discussed in the pickaxe book (Programming Ruby) which is 
available both in book form through amazon and online at 
http://www.rubycentral.com/book/.  If you look at the Ruby.new section 
in Programming Ruby you will find more description of the "#{}" syntax.

-Matthew Margolis