From: Gavin Sinclair Date: 2004-06-29T08:01:55+09:00 Subject: Re: Is it considered Harmful? On Tuesday, June 29, 2004, 4:04:21 AM, Sean wrote: >> You're missing his point. >> >> If I call Array.new, I certainly get an array whose #initialize >> has been called. >> >> But if I then do arr.class = Net::HTTP, then Net:HTTP#initialize >> does NOT get called (e.g., to set the host name or whatever). > Ah...I see why I haven't connected with that issue now. I think of this as a > "buyer beware" issue. If you change an existing object's class, be sure you > change it to something that understands the object it is receiving. I think > even #become would have these problems. No it wouldn't. Objects are supposed to represent data and behaviour. #become keeps both intact. #class= changes only the behaviour. If something does't work after #become, it's not because the use of #become introduced an inconsistency. The same cannot be said of #class=. That's not necessarily a point against it... > Even using include could introduce methods to a class which didn't > initialize instance data the way it expects. ...as this demonstrates. Ruby contains lots of features that make it easy to write broken programs. #class= should be considered in that light. I don't see it as being very useful (stateless behaviour can be elegantly captured by modules), but I'm sure it could be. Gavin