What would be the ruby equivalent of the following perl script? I
use the idiom often for quick templating tasks. It finds every
occurrence of %%WHATEVER%% in $source and replaces it with the results
of a subroutine call to sub whatever (lowercased) and is passed
$variable.
$source=~ s/%%(.*?)%%/lc($1)->($variable)/eg ;
Thanks in advance.
BTW: I asked this question on the python newsgroup a while ago (with
respect to how this would be accomplished in python) and received some
very informative responses, in case anyone is interested in knowing
how this would be accomplished in python.
probably not very idiomatic, and EVIL
source.gsub!(/%%([A-Z]*)%%/) { eval “#{$1.downcase} variable” }
(take care of the binding in use)
···
On Thu, Dec 12, 2002 at 04:40:53AM +0900, Jonah wrote:
What would be the ruby equivalent of the following perl script? I
use the idiom often for quick templating tasks. It finds every
occurrence of %%WHATEVER%% in $source and replaces it with the results
of a subroutine call to sub whatever (lowercased) and is passed
$variable.
$source=~ s/%%(.*?)%%/lc($1)->($variable)/eg ;
–
_ _
__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_
_ \ / ` | ’ \
) | (| | |__ \ | | | | | (| | | | |
.__/ _,|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
- JHM wonders what Joey did to earn “I’d just like to say, for the record,
that Joey rules.”
– Seen on #Debian