From 288aa250abc9fc20bc13cff2d6da74d6bee477af Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Thu, 25 Aug 2011 20:11:54 -0700 Subject: [PATCH] Add an id#ancestors() helper function, to walk up the inheritance chain. --- id.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/id.js b/id.js index 68a2dfa..f9f977a 100644 --- a/id.js +++ b/id.js @@ -122,6 +122,20 @@ proto.setClass = function setClass (newClass) { return exports._wrapClass(core.object_setClass(this.pointer, newClass.pointer)); } +/** + * Walks up the inheritance chain and returns an Array of Strings of + * superclasses. + */ +proto.ancestors = function ancestors () { + var rtn = [] + , c = this.getClass() + while (c) { + rtn.push(c.getName()) + c = c.getSuperclass() + } + return rtn +} + /** * Returns an Array of Strings of the names of methods that the current object * will respond to. This function can iterate through the object's superclasses