mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 05:25:34 +02:00
13 lines
324 B
Ruby
13 lines
324 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Polyfill for String#byteindex, which didn't exist until Ruby 3.2.
|
|
if !("".respond_to?(:byteindex))
|
|
String.include(
|
|
Module.new {
|
|
def byteindex(needle, offset = 0)
|
|
charindex = index(needle, offset)
|
|
slice(0...charindex).bytesize if charindex
|
|
end
|
|
}
|
|
)
|
|
end
|