On Sat, Jun 26, 2004 at 12:48:28AM +0900, Sean O'Dell wrote: > > If you think that the possiblity to crash ruby is not a technical reason, > > then you are right it don't exist solid technical reason. > > You're wrong on that. It wouldn't crash Ruby to change the class of an > object. Yes it will, in the current implementation. You can download evil.rb, remove the safety checks in Object#become and try a = Object.new a.class = String a.size # or some other method from String This is so because rb_str_* methods will treat the internal structure as a RString, even though it's just a RObject. > Objects already change their class when you turn them into > singletons. Changing it to any class of your choosing would be even simpler, > since creating a singleton involves inheriting all the old class methods; > changing a class wouldn't require all that work. While your description of the internal working of Ruby's singletons is accurate (I'd say 'klass field' and not 'class', though), it's doesn't change the fact that an unrestricted Object#become *is not* safe in all circumstances, esp. when it involves Hash, Array, Regexp, File, String, etc... objects, which are treated differently internally. -- Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Not only Guinness - Linux is good for you, too. -- Banzai on IRC