Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Ruby::Prism::CodeUnitsCache#[]
[](byte_offset)
lib/ruby/prism/parse_result.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/ruby/prism/parse_result.rb, line 325
def [](byte_offset)
@cache[byte_offset] ||=
if (index = @offsets.bsearch_index { |offset| offset > byte_offset }).nil?
@offsets << byte_offset
@counter.count(0, byte_offset)
elsif index == 0
@offsets.unshift(byte_offset)
@counter.count(0, byte_offset)
else
@offsets.insert(index, byte_offset)
offset = @offsets[index - 1]
@cache[offset] + @counter.count(offset, byte_offset - offset)
end
end
See also
.new