Created
August 5, 2011 21:47
-
-
Save sergeyenin/1128600 to your computer and use it in GitHub Desktop.
ClassModule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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