Brian Candler
5/4/2007 10:36:00 AM
On Fri, May 04, 2007 at 07:15:44PM +0900, Robert Dober wrote:
> 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.
...
> Againts: Well it is a change request for very little functionality,
> but if enough people like it and if Matz likes it ;)
This is perhaps a good example of where making your own extensions to
built-in classes, to make your own domain-specific language, is a good idea.
That is, if you're doing it so many times that ,"" is getting hard to type,
then why not shrink 'gsub' too while you're at it?
class String
def -(re)
gsub(re,'')
end
end
a = "some string"
p a - /s/