Skip to content

Instantly share code, notes, and snippets.

@mwmitchell
Created April 22, 2009 03:50
Show Gist options
  • Save mwmitchell/99570 to your computer and use it in GitHub Desktop.
Save mwmitchell/99570 to your computer and use it in GitHub Desktop.
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