module T::Private::Methods
def self.install_hooks(mod)
def self.install_hooks(mod) return if @installed_hooks.include?(mod) @installed_hooks << mod if mod == TOP_SELF # self at the top-level of a file is weirdly special in Ruby # The Ruby VM on startup creates an `Object.new` and stashes it. # Unlike when we're using sig inside a module, `self` is actually a # normal object, not an instance of Module. # # Thus we can't ask things like mod.singleton_class? (since that's # defined only on Module, not on Object) and even if we could, the places # where we need to install the hooks are special. mod.extend(SingletonMethodHooks) # def self.foo; end (at top level) Object.extend(MethodHooks) # def foo; end (at top level) return end # See https://github.com/sorbet/sorbet/pull/3964 for an explanation of why this # check (which theoretically should not be needed) is actually needed. if !mod.is_a?(Module) return end if mod.singleton_class? mod.include(SingletonMethodHooks) else mod.extend(MethodHooks) end mod.extend(SingletonMethodHooks) end