From: Charles Comstock Date: 2003-11-23T09:30:11+09:00 Subject: Re: Destructive type conversion (to_i!, to_f!) On Sun, 23 Nov 2003, David A. Black wrote: > The built-in ! methods do in-place operations on the same object, > whereas the thing you're looking to do is to reassign the variable to > a different object. So it's really taking place at a different > logical and/or semantic level. > > However, I think there was discussion recently, and possibly in the > past also, of the idea of: > > obj .= method > > which would be shorthand for > > obj = obj.method > > That's more analogous to the > > obj += other > > form, which is shorthand for > > obj = obj + other # i.e., reassignment to variable, not in-place > # modification > Hmm, I'm not sure about .= as a syntax personally. It makes sense in light of += and -= but symantically it seems weird with regard to objects since basically it's an alternate form of . Since . effectively means "send" what does .= mean in that context? It would be nice in terms of being short and sweet, but not so nice in terms of symantics. I did think of the issue of not technically changing the existing object when using a destructive type change. The key issue of this is that I viewed it as a type change and not a object reassignment. Technically since the prevailing view of ruby objects is the 'duck typing' model you should be able to change the type of an object instead of reassigning. By this I mean you should be able to take a specific duck and turn it into a fish. And then have it derive from whatever classes fish derive from and no longer derive from whatever a duck derives from. So you ought to be able to extend an object and unextend an object. Or I may just be making up silly ideas, I don't know. I guess a better summery is that I viewed the type as something that was changeable on an object and so therefor a.to_f! would still be changing THAT object. This may not be the general view on types in ruby. Charles Comstock