On 5/4/07, Yukihiro Matsumoto <matz / ruby-lang.org> wrote:
> Hi,
>
> In message "Re: RCR?"
>     on Fri, 4 May 2007 19:15:44 +0900, "Robert Dober" <robert.dober / gmail.com> writes:
>
> |Currently I am writing lots of code like this:
> |
> |"some string".gsub(/s/,"") # I am using more complex rgxs therefore
> |# String#delete is not an option.
> |
> |I would like to write
> |"some string".gsub(/s/)
> |instead.
> |
> |There are two roads to walk:
> |(a) Allow String#delete to have a Regex
> |(b) Give String#gsub, String#sub, String#gsub! and String#sub! the
> |empty string as default for parameter replacement.
>
> Could you tell me why you want to reduce tiny three letters?
No I cannot not and even if I could I would not because I do not feel
qualified to do some
lobbying. I just like it, and if others do not I will not talk about it anymore.
And you are of course one of the most important others.
> I feel like explicit empty replacement describes user's intention more
> precisely than omitted default empty.
And the implicit parameter is dangerous as it might mask errors where
the user just forgot the second parameter.
The importance of the replacement string might as well not justify that danger.
>
> How do you think comparing those two:
>
>   "some string".gsub(/s/,"")
>   "some string".gsub(/s/)

I just love the second, but I see the dangers and problems too.
I just need to communicate to see beyond things. Thank you a lot of
wasting your time in order to allow me to do that.

I guess I always learn a lot from my intentional RCRs :)

There would be another road to talk of course but it will brake to much code.

String#delete_all( str_or_rgx )
String#delete_first( str_or_rgx)
String#delete_last(str_or_rgx) # (1)
String#delete an alias to String#delete_all
 and of course the same thing for the ! variations of these methods

(1) would it not be nice to get rid of the
  "robert is stupid, robert created ruby".reverse.sub("trebor", "ztam").reverse
   idiom ;)

Cheers
Robert
>
>                                                         matz.
>
>


-- 
You see things; and you say Why?
But I dream things that never were; and I say Why not?
-- George Bernard Shaw