Okay... how do I get the name of the superclass from within the class?
For example: how can I tell from within the Dog Class that Dog is a
subclass of Animal. How can I get the name "Animal" without using
instanceof?
Edd
On Nov 19, 2:05 pm, "Nicolás Sanguinetti" <[EMAIL PROTECTED]> wrote:
> You have to call it on the Class, not the instances, and the "klass()"
> returned works fine. With your example:
>
> var duck = new (Dog.superclass)("ducky");
> duck instanceof Animal
>
> >>> true
>
> Best,
> -Nicolas
>
> On Nov 19, 2007 11:59 AM, redheat <[EMAIL PROTECTED]> wrote:
>
>
>
> > Any ideas why I only get "klass()" returned when I try to access
> > ClassName.superclass or ClassName.subclasses, and "undefined" when I
> > access class_instant.superclass or class_instant.subclasses?
>
> > I'm probably doing something really stupid.
>
> > var Animal = Class.create({
> > initialize: function(name) {
> > this.name = name;
> > }
> > });
>
> > var Dog = Class.create(Animal, {
> > initialize: function($super, name) {
> > $super(name);
> > },
>
> > bark: function() {
> > return this.name + ' said "Woof!"';
> > }
> > });
>
> > var poodle = new Dog('Jack');
> > poodle.superclass; //--> undefined
> > Dog.superclass; //--> klass()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---