Files
klayout/testdata/vendor/ruby/test/unit/util/method-owner-finder.rb
T
Matthias Koefferlein 585d0941bb RBA Unit test enhancements
- Include a copy of the unit test framework so we're no longer
  depending on incompatible versions for Ruby 1 and 2.
- Avoid duplication of path entries in unit tests
2017-07-23 23:03:21 +02:00

29 lines
728 B
Ruby

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