Skip to content

Instantly share code, notes, and snippets.

@djsun
Created October 16, 2009 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djsun/211995 to your computer and use it in GitHub Desktop.
Save djsun/211995 to your computer and use it in GitHub Desktop.
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