Showing posts with label superclass. Show all posts
Showing posts with label superclass. Show all posts

Wednesday, August 17, 2011

Get sub classes and super class in ruby on rails

Get the sub classes from super class by using command

subclasses_of(Parent Class Name)

Get the super class from sub class by using command

Child Class Name.superclass

eg. Class User
      end

     Class Admin < User
     end
    
     Class Employee < User
     end

Lets we have User as super class and which inherited by sub classes Admin and Employee respectively.

If we need to get child classes by using subclasses_of(User) and to get parent class by using Admin.superclass.