Dear Shoaib Ahmed,

Following the answer of Arun Sharma...


On Wed, Feb 5, 2014 at 5:08 PM, Arun kant sharma <iarunkant / gmail.com> wrote:
> obj.class.ancestors

or

obj.class.ancestors - obj.class.included_modules

But if you are just willing a help at constructing the loop to iterate
through each superclass until it gets a nil...

The code will be something like this.

def superclasses(object)
  super_classes = []
  current_class = object.class
  super_classes.push current_class
  while current_class.superclass # When on BasicObject it will return
nil breaking the loop
    current_class = current_class.superclass
    super_classes.push current_class
  end
  super_classes
end

# Writing it with while one line syntax

def superclasses(object)
  super_classes = []
  current_class = object.class
  super_classes.push current_class
  super_classes.push current_class while current_class =
current_class.superclass
  super_classes
end

Best regards,
Abinoam Jr.

> is probably you are looking for.