matz / netlab.co.jp (Yukihiro Matsumoto) writes:

> Hi,
> 
> In message "[ruby-talk:03381] Re: chomp!"
>     on 00/06/13, Dave Thomas <Dave / thomases.com> writes:
> 
> |> |chomp:
> |> |       Equivalent to $_.chomp!(aString), except nil is never
> |> |       returned. If $_ is changed, the new version is returned,
> |> |       otherwise a copy of the original value is returned. See
> |> |       String#chomp! on page 1.
> |> 
> |>         Equivalent to `$_ = $_.chomp(aString)'.
> |
> |Well yes... but our version uses more words, so it must be better ;-)
> 
> Are you saying the same thing?  Well, sorry.

I think so, but yours is better (and is now the new wording)

> By the way, do you prefer the behavior like:
> 
>   str = $_.dup
>   if str.chomp!
>     $_ = str
>   end

Even better would be an implementation (in C) like:

    if $_.chomp?
       str = $_.dup.chomp!
    end

where chomp? did the initial setup for the chomp, and returned true if 
the string would be modified, and then chomp! could use that work to
change the string.

On performance tests I've been doing, string object creations are a
BAD THING, so eliminating that dup would be good.


Regards


Dave