File Manager

Current Path : /usr/lib/ruby/gems/3.0.0/gems/test-unit-3.3.7/lib/test/unit/util/
Upload File :
Current File : //usr/lib/ruby/gems/3.0.0/gems/test-unit-3.3.7/lib/test/unit/util/method-owner-finder.rb

module Test
  module Unit
    module Util
      module MethodOwnerFinder
        module_function
        def find(object, method_name)
          method = object.method(method_name)
          return method.owner if method.respond_to?(:owner)

          if /\((.+?)\)\#/ =~ method.to_s
            owner_name = $1
            if /\A#</ =~ owner_name
              ObjectSpace.each_object(Module) do |mod|
                return mod if mod.to_s == owner_name
              end
            else
              owner_name.split(/::/).inject(Object) do |parent, name|
                parent.const_get(name)
              end
            end
          else
            object.class
          end
        end
      end
    end
  end
end

File Manager Version 1.0, Coded By Lucas
Email: hehe@yahoo.com