[#4595] New block syntax — Daniel Amelang <daniel.amelang@...>

I'm really sorry if this isn't the place to talk about this. I've

25 messages 2005/03/21
[#4606] Re: New block syntax — "David A. Black" <dblack@...> 2005/03/21

Hi --

[#4629] Re: New block syntax — "Sean E. Russell" <ser@...> 2005/03/30

On Monday 21 March 2005 16:17, David A. Black wrote:

[#4648] about REXML::Encoding — speakillof <speakillof@...>

Hi.

15 messages 2005/03/31
[#4659] Re: about REXML::Encoding — "Sean E. Russell" <ser@...> 2005/04/04

On Thursday 31 March 2005 09:44, speakillof wrote:

Re: rb_reg_quote weirdness

From: Sam Roberts <sroberts@...>
Date: 2005-03-15 13:26:40 UTC
List: ruby-core #4568
Quoting mailing-lists.ruby-core@rawuncut.elitemail.org, on Tue, Mar 15, 2005 at 09:26:12PM +0900:
> * Sam Roberts (Mar 15, 2005 13:00):
> > > > My documentation for Regexp::quote(str) says that a copy of str is
> > > > returned, yet if str doesn't contain any metacharacters, str itself
> > > > is returned.
> 
> > > For efficiency, avoiding unnecessary copy is sought.  For
> > > consistency, and safety (from in-place string modification), all
> > > time copy is better.  I chose the former.  But I'm still open for
> > > input.
> 
> > I think your choice is right. If people want to duplicate the string,
> > they can do str.quote.copy, or something.
> 
> You mean Regexp.quote(str).dup
>
> It's of course a problem having to decide whether the dup is necessary
> or not.  What if there was a need for some quoting and the return-value
> of Regexp::quote actually is freshly allocated?

But not an unsolvable problem. If you really need a copy (despite that
it is inefficient), but don't want to be so inefficient as to create an
unnecessary copy:

  def Regexp.quote_dup(s)
    q =  Regexp.quote(s)
    if q.equal?(s)
      q.dup
    else
      q
    end
  end

Cheers,
Sam


In This Thread

Prev Next