On 2006-07-08, transfire / gmail.com <transfire / gmail.com> wrote:
>
> Jeremy Henty wrote:
>
>> ... the convention already exists that Klass(x) means "coerce x to
>> an instance of Klass", rather than "call Klass.new()".  As least it
>> does for many values of Klass, so to make all instances of Klass()
>> synonyms for Klass.new() would be seriously incompatible.
>
> Not so. Just becaue they would default to Klass.new does not mean
> they could not be overriden with a variation of functionality -- as
> is the case with some of those built in.

Maybe, but how would it work?  On what criterion would you override?
You'd want all calls to Klass() with a single argument to be
interpreted as coercion, since one might in principle want to coerce
any object to a <#Klass>.  So what do you do when it's natural to call
Klass.new with one argument?  Maybe you could work around it, but I'd
be worried you'd be making a messy situation even worse.

I don't object to you doing this with your own classes, I just don't
see a good way of extending this convention to *all* Ruby classes, at
least not without breaking compatibility enough to rule it out for
Ruby 1.x .

Regards, 

Jeremy Henty