Hi,
In message "[ruby-talk:01195] Re: Semantics of chomp/chop"
on 00/01/28, Dave Thomas <Dave / thomases.com> writes:
|I was wondering why copy it at all, as all four methods are allowed to
|alter $_.
They are different. For exapmle:
foo = $_ = "foo\n"
chomp
p foo #=> "foo\n" -- unchanged
p $_ #=> "foo"
foo = $_ = "foo\n"
chomp!
p foo #=> "foo"
p $_ #=> "foo"
See? Non-bang versions leave original strings unchanged.
|I don't know if it's necessary, but you _could_ have [g]sub! and
|cho[m]p! always return the string, and set $& to whatever was
|changed. If $& is nil, then no change was made.
It may be better to return strings always. But I think `$&' is not
sufficient, because it is for `match', not `modifys'.
matz.