Regexp challenge

Just out of curiosity, for fun:

Whats the rubyest ruby program you can code for opening a directory of
files and replacing a particular string in all files (if found) with
another string?

Lets suppose that all files in directory are text and the string to
search
for is “target”, and replace string is “practice”.

Csmr

On 5/23/07, Casimir P. [email protected] wrote:

You go first.

On May 23, 2007, at 11:14 AM, Casimir P. wrote:

Whats the rubyest ruby program you can code for opening a directory of
files and replacing a particular string in all files (if found) with
another string?

Lets suppose that all files in directory are text and the string to
search
for is “target”, and replace string is “practice”.

From inside the directory in question:

$ ruby -pi -e ‘gsub(“target”, “practice”)’ *

James Edward G. II

On May 23, 2007, at 2:39 PM, Tim P. wrote:

search
learned three new things.
I come from Perl where tricks like that our very common,
which is probably just proof that my solution fails “the rubyest
ruby” requirement of the question.

James Edward G. II

On 5/23/07, James Edward G. II [email protected] wrote:

I come from Perl where tricks like that our very common,
which is probably just proof that my solution fails “the rubyest
ruby” requirement of the question.

Well, you did fail to use a regular expression :wink:

TwP

On 5/23/07, James Edward G. II [email protected] wrote:

From inside the directory in question:

$ ruby -pi -e ‘gsub(“target”, “practice”)’ *

James Edward G. II

And we have a winner! James you never cease to amaze me. I just
learned three new things.

TwP

On 5/23/07, James Edward G. II [email protected] wrote:

I come from Perl where tricks like that our very common,
which is probably just proof that my solution fails “the rubyest
ruby” requirement of the question.

Well, I was tempted to comment that your solution seemed more perlish
than rubyish, but it was against my better nature.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs