Created
April 22, 2009 03:50
-
-
Save mwmitchell/99570 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 ExtendedMeta | |
def extended_by | |
ancestors = class << self; ancestors end | |
ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] | |
end | |
# just like kind_of? but can use a string instead of a module/constant | |
def extended_by?(mod) | |
begin | |
scope = mod.split('::').select do |v| | |
! v.empty? | |
end.inject(Kernel) do |scope, const_name| | |
scope.const_get(const_name) | |
end | |
extended_by.include?(scope) | |
rescue NameError | |
false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment