From: Clemens Hintze Date: 2000-03-17T10:54:54+01:00 Subject: [ruby-talk:01962] Re: Ruby Syntax similar to other languages? Yukihiro Matsumoto writes: > > In message "[ruby-talk:01954] Re: Ruby Syntax similar to other languages?" > on 00/03/17, "Conrad Schneiker" writes: > > |This is one place where I would very much prefer a vi/sed/perl > |scheme! > | > |Is it possible to add something (standard) so that we could do: > | > |foo.s > |foo.s! > | > |with an optional extra parameter string for perl-ish modifier > |characters such as "g"? > > What's the benefit of foo.s(/pat/, "repl", "g") over foo.gsub(/pat/, > "repl")? Only to have not *two* methods, but only one. But then I would prefer an additional flags argument like this: class String LOCAL = 0 GLOBAL = 1 INPLACE = 2 Subs = [:sub, :gsub, :sub!, :gsub!] def s(pat, repl, flags = LOCAL) send Subs[flags], pat, repl end end str = "hello world" p str str.s /el/, "al", String::INPLACE p str But I think I can also live with the current 4 methods :-) \cle