GarethAtFlignet
2008-Feb-18 11:28 UTC
Retrieving the class name and names of parent classes
If you take the code: var Vehicle = Class.create({ initialize: function() { alert(***class name***); } }); var Car = Class.create(Vehicle, { initialize: function() { alert(***class name***); alert(***parent class name***); } }); var t1 = new Vehicle("A Vehicle"); var t2 = new Car("A Car"); How would the output the name od the current class and retrieve the name of the parent class in the relevent sections? Any help appreciated, many thanks. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Richard Quadling
2008-Feb-18 12:00 UTC
Re: Retrieving the class name and names of parent classes
On 18/02/2008, GarethAtFlignet <garethinwales-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > If you take the code: > > var Vehicle = Class.create({ > initialize: function() { > alert(***class name***); > } > }); > > var Car = Class.create(Vehicle, { > initialize: function() { > alert(***class name***); > alert(***parent class name***); > } > }); > > > > var t1 = new Vehicle("A Vehicle"); > var t2 = new Car("A Car"); > > How would the output the name od the current class and retrieve the > name of the parent class in the relevent sections? > > Any help appreciated, many thanks.There isn''t a native way. Instead, you have to add a param (say selfClass) in which you manually store the current class name and a method (getParentClass()) to extract get the $super.selfClass. If the method was built in at low level (say object), then every object would have the ability to find it''s parent class. You may also need a getParentClasses() method. Also, as prototype sort of supports multiple inheritence (mixins I think is the term), then a single class COULD actually be made from several other classes, so this may need to be considered (and each of those classes could have multiple parents). -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
GarethAtFlignet
2008-Feb-18 13:23 UTC
Re: Retrieving the class name and names of parent classes
Thanks Richard. Apologies for the confusion but when I said parent I did in fact mean the superclass (e.g. Vehicle is the superclass of Car). On 18 Feb, 12:00, "Richard Quadling" <rquadl...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 18/02/2008, GarethAtFlignet <garethinwa...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > > If you take the code: > > > var Vehicle = Class.create({ > > initialize: function() { > > alert(***class name***); > > } > > }); > > > var Car = Class.create(Vehicle, { > > initialize: function() { > > alert(***class name***); > > alert(***parent class name***); > > } > > }); > > > var t1 = new Vehicle("A Vehicle"); > > var t2 = new Car("A Car"); > > > How would the output the name od the current class and retrieve the > > name of the parent class in the relevent sections? > > > Any help appreciated, many thanks. > > There isn''t a native way. > > Instead, you have to add a param (say selfClass) in which you manually > store the current class name and a method (getParentClass()) to > extract get the $super.selfClass. > > If the method was built in at low level (say object), then every > object would have the ability to find it''s parent class. You may also > need a getParentClasses() method. > > Also, as prototype sort of supports multiple inheritence (mixins I > think is the term), then a single class COULD actually be made from > several other classes, so this may need to be considered (and each of > those classes could have multiple parents). > > -- > ----- > Richard Quadling > Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!"--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
GarethAtFlignet
2008-Feb-18 19:38 UTC
Re: Retrieving the class name and names of parent classes
Managed to modify some code by Tobias Nurmiranta to achieve what I needed. see: http://groups.google.com/group/rubyonrails-spinoffs/browse_thread/thread/b712bb66a1866f74 --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---