Created
August 1, 2010 19:03
-
-
Save jarmo/503646 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Object | |
def descendant?(parent) | |
parent = parent.class unless parent.is_a?(Class) || parent.is_a?(Module) | |
self.class.to_s.index("#{parent}::") == 0 | |
end | |
end | |
module MyModule | |
module AnotherModule | |
class MyClass | |
end | |
class AnotherClass | |
end | |
end | |
end | |
module MyAnotherModule | |
end | |
m = MyModule::AnotherModule::MyClass.new | |
p m.descendant?(MyModule) | |
p m.descendant?(MyModule::AnotherModule) | |
p m.descendant?(MyModule::AnotherModule::MyClass) | |
p m.descendant?(m) | |
a = MyModule::AnotherModule::AnotherClass.new | |
p m.descendant?(a) | |
p m.descendant?(MyAnotherModule) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment