From: Ned Konz Date: 2001-08-08T14:49:13+09:00 Subject: [ruby-talk:19351] Re: Perl/Python/Ruby common backend (Parrot, can Ruby play too?) On Tuesday 07 August 2001 10:37 pm, Mathieu wrote: > Ruby has this thing called "mixins" that afaik is not in Python (unless > it's quite recent) and is not in Perl. In Perl you have multiple > inheritance, but the dispatch is C++-style, so calling SUPER looks > always upwards. Ruby backtracks in the method lookup. (Damian wants that > in Perl6) I don't understand what you mean. In Perl, the method lookup is first in the current class, and then depth-first through the @ISA (parent) list. Calling, say, $self->SUPER::method merely skips the current class (and only works if written in the namespace (package) of the class that's being defined, not dynamically as I've wanted it to). I could see wanting to do a breadth-first search through @ISA, or make SUPER work outside of the original namespace. > Ruby also has metaclasses (singleton classes that inherit from the Class > class). Perl doesn't even have Class objects. We've (Toby Everett and I) added a reflection layer to Perl, at least. And added the ability to smoothly make singleton classes, or to adjust inheritance dynamically. > Oh, Ruby also has singleton classes, which implement adding methods and > superclasses to objects. We did this for Perl also (see Class::Prototyped). Works fine, actually. You can inherit from these singleton classes and/or regular classes, and change the inheritance on the fly. > Ruby has closures, which allow to modify existing variables of the > enclosing binding. For closures there is a special slot "&" in every > message that allows for the #each{} kind of methods. Perl has closures, of course. > This is a small and possibly incomplete list. > > OTOH, Ruby *doesn't* allow to change an object's class, unlike Perl and > Python. The exception to that is when a object has class=Foo and > changes to class=(new singleton class inheriting from Foo). You know, I've been meaning to ask how to do this (change the class of an object). Is there something akin to Smalltalk's "become:" in which two objects swap identities? That's one way to do this, of course. Also, how can one change the superclass of an existing class in Ruby? -- Ned Konz currently: Stanwood, WA email: ned@bike-nomad.com homepage: http://bike-nomad.com