123456789_123456789_123456789_123456789_123456789_

Module: Test::Unit::Util::MethodOwnerFinder

Relationships & Source Files
Defined in: lib/test/unit/util/method-owner-finder.rb

Class Method Summary

Class Method Details

.find(object, method_name) (mod_func)

[ GitHub ]

  
# File 'lib/test/unit/util/method-owner-finder.rb', line 6

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