Created
October 16, 2009 19:27
-
-
Save djsun/211995 to your computer and use it in GitHub Desktop.
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 Helper | |
def self.parent(scope) | |
chain = scope.name.split("::")[0 ... -1] | |
chain.reduce(Object) { |m, o| m.const_get(o) } | |
end | |
end | |
module Family | |
def sibling(string) | |
Helper.parent(self).const_get(string) | |
end | |
end | |
module A | |
module B | |
class C | |
end | |
class D | |
extend Family | |
puts sibling "C" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment