From: Erno Kuusela Date: 2001-08-08T13:35:26+09:00 Subject: [ruby-talk:19342] Re: Perl/Python/Ruby common backend (Parrot, can Ruby play too?) In article <9kpeft$kbm$1@slb4.atl.mindspring.net>, "Andrew Dalke" writes: [...] | She chose Tcl (with an | object extension) over Python because Python's ability to add | new methods is not obvious[*] and because existing instances | are not updated with the new class definitions you can do this: >>> class Spam: .... def eat(self): .... print 'yum' .... >>> spam = Spam() >>> spam.eat() yum >>> >>> def new_eat(self): .... print 'yech' .... >>> Spam.eat = new_eat >>> >>> spam.eat() yech if you want it to attach the new method to the same class in face of inheritance, you need "spam.eat.im_class.eat = new_eat" - you could wrap it in a function if that look too much like a magic incanatation for your audience. if you actually want to replace the underlying classes of all instances, you could probably cook something up with the weakref module and calling a registration function in __init__... -- erno