ruby/lib/prism/polyfill/scan_byte.rb
Nobuyoshi Nakada 0e604623d8 [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
2025-11-14 13:47:49 +00:00

15 lines
294 B
Ruby

# frozen_string_literal: true
require "strscan"
# Polyfill for StringScanner#scan_byte, which didn't exist until Ruby 3.4.
if !(StringScanner.method_defined?(:scan_byte))
StringScanner.include(
Module.new {
def scan_byte # :nodoc:
get_byte&.b&.ord
end
}
)
end