-
-
Save eregon/61ff7e20aaaa5af35a3e6401603d1f7f 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
def enclosing_module | |
begin | |
mod = self.name.split("::")[0..-2].inject(Object) { |obj, c| obj.const_get(c) } | |
if mod < FFI::Library || mod < FFI::Struct | |
mod | |
elsif mod.respond_to?(:find_type) | |
arity = mod.method(:find_type).arity | |
# Only consider a #find_type that accepts a single argument. | |
# MakeMakefile#find_type from 'mkmf' needs 2 arguments and should be ignored. | |
if arity == 1 || arity == -1 || arity == -2 | |
mod | |
end | |
end | |
rescue Exception | |
nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment