Skip to content

Instantly share code, notes, and snippets.

@sergeyenin
Created August 5, 2011 21:47
Show Gist options
  • Save sergeyenin/1128600 to your computer and use it in GitHub Desktop.
Save sergeyenin/1128600 to your computer and use it in GitHub Desktop.
ClassModule
module ClassModule
#all successors excluding self
def successors(klass=self.name.to_s)
descendants = []
begin
ObjectSpace.each_object(class << eval(klass);self;end) do |found|
descendants << found
end
rescue Exception=>e
descendants << klass
end
#return successors exclude class itself
descendants.reject{|x| x.to_s == klass.to_s}
end
#just proximate successors
def subclasses(klass=self.name.to_s)
successors(klass).select{|x| eval(klass).to_s == x.superclass.to_s}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment