[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:01962] Re: Ruby Syntax similar to other languages?

From: Clemens Hintze <clemens.hintze@...>
Date: 2000-03-17 09:54:54 UTC
List: ruby-talk #1962
Yukihiro Matsumoto writes:
> 
> In message "[ruby-talk:01954] Re: Ruby Syntax similar to other languages?"
>     on 00/03/17, "Conrad Schneiker" <schneiker@jump.net> 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

In This Thread