[ruby/prism] 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/prism/commit/6da384dd0e
This commit is contained in:
Nobuyoshi Nakada 2025-11-14 10:51:20 +09:00 committed by git
parent f4b6a5191c
commit 0e604623d8

View File

@ -3,7 +3,7 @@
require "strscan"
# Polyfill for StringScanner#scan_byte, which didn't exist until Ruby 3.4.
if !(StringScanner.instance_methods.include?(:scan_byte))
if !(StringScanner.method_defined?(:scan_byte))
StringScanner.include(
Module.new {
def scan_byte # :nodoc: