Basically, apply a regex to a string, and for every match, call get($1) and
replace the match with the return value of the get(). get() comes from
LWP::Simple, and simply fetches the content at the given URL.
My Ruby-fu is failing me at coming up with a relatively concise yet readable
way to do this in Ruby. My implementation is, I am sure, much longer than
necessary.
And....nevermind. I figured out where I was being thick. gsub with a block
works nicely.
Kirk Haines
···
On Fri, 9 Jul 2004 01:21:29 +0900, Kirk Haines wrote
My Ruby-fu is failing me at coming up with a relatively concise yet
readable way to do this in Ruby. My implementation is, I am sure,
much longer than necessary.
On Fri, 9 Jul 2004 01:21:29 +0900, Kirk Haines wrote
My Ruby-fu is failing me at coming up with a relatively concise yet readable way to do this in Ruby. My implementation is, I am sure, much longer than necessary.
So, anyone have any ideas? How would you do this?
And....nevermind. I figured out where I was being thick. gsub with a block works nicely.
Kirk Haines
We ran into the same question earlier today. Maybe the documentation for String.sub() should mention String.gsub(). I think it would have been more intuitive to have an optional parameter to sub() for global/case-insenstive/etc.
"Randy Lawrence" <jm@zzzzzzzzzzzz.com> schrieb im Newsbeitrag
news:fqlHc.1176$%_.703@newssvr32.news.prodigy.com...
Kirk Haines wrote:
>
>
>>My Ruby-fu is failing me at coming up with a relatively concise yet
>>readable way to do this in Ruby. My implementation is, I am sure,
>>much longer than necessary.
>>
>>So, anyone have any ideas? How would you do this?
>
>
> And....nevermind. I figured out where I was being thick. gsub with a
block
> works nicely.
>
>
> Kirk Haines
>
>
>
We ran into the same question earlier today. Maybe the documentation
for String.sub() should mention String.gsub().
Good point.
I think it would have
been more intuitive to have an optional parameter to sub() for
global/case-insenstive/etc.
Case sensitivity is controlled by a regular expression flag.
About gsub vs. sub with a paramter that controls global replacement: while
that might mimic what vi does, it's generally considered better style to
have separate methods if behavior differs than to have a single method
whose behavior is controlled by flags. Also it's more efficient, too.
Kind regards
robert
···
> On Fri, 9 Jul 2004 01:21:29 +0900, Kirk Haines wrote
We ran into the same question earlier today. Maybe the documentation
for String.sub() should mention String.gsub().
Funny, I wrote "see gsub for global occurrences" in "Programming Ruby's"
chapter 22 about half an hour ago. It ought to have been there already,
IMNSHO.
Graham