[ruby/rubygems] Use method_defined? instead of instance_methods.include?

While the latter creates an intermediate array of all method names
including all ancestors, the former just traverse the inheritance
chain and can stop if found once.

https://github.com/ruby/rubygems/commit/b291070b3b
This commit is contained in:
Nobuyoshi Nakada 2025-11-14 10:57:18 +09:00 committed by git
parent 256b4722a0
commit e39385bf84
2 changed files with 2 additions and 2 deletions

View File

@ -25,7 +25,7 @@ class TestGemExtCargoBuilderLinkFlagConverter < Gem::TestCase
}.freeze
CASES.each do |test_name, (arg, expected)|
raise "duplicate test name" if instance_methods.include?(test_name)
raise "duplicate test name" if method_defined?(test_name)
define_method(test_name) do
assert_equal(expected, Gem::Ext::CargoBuilder::LinkFlagConverter.convert(arg))

View File

@ -2,7 +2,7 @@
require_relative "package/tar_test_case"
unless Gem::Package::TarTestCase.instance_methods.include?(:assert_ractor)
unless Gem::Package::TarTestCase.method_defined?(:assert_ractor)
require "core_assertions"
Gem::Package::TarTestCase.include Test::Unit::CoreAssertions
end