From: Sean O'Dell Date: 2004-06-26T01:44:37+09:00 Subject: Re: Is it considered Harmful? On Friday 25 June 2004 08:57, Dave Thomas wrote: > On Jun 25, 2004, at 10:48, 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. 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. > > Singletons are effectively subclasses of the original. > > irb(main):001:0> a = /cat/ > => /cat/ > irb(main):002:0> def a.speak; "meiow"; end > irb(main):005:0> a.speak > => "meiow" > irb(main):006:0> a.class > => Regexp > > How would you handle > a = /cat/ > a.class = File > a.read > > It's a brave man that calls Guy 'wrong,' so I'm looking forward to > seeing your implementation of this. How is that any different from: class Regexp include Enumerable end a = /cat/ a.each You can do all sorts of crazy things in Ruby. Buyer beware. Enter at your own risk. Sean O'Dell