class Prism::Relocation::CodeUnitOffsetsField - Documentation for Ruby 4.0
Description: class Prism::Relocation::CodeUnitOffsetsField: A field representing the start and end code unit offsets.
Keywords: ruby,class,Prism::Relocation::CodeUnitOffsetsField

🔍

No recent searches

# class Prism::Relocation::CodeUnitOffsetsField

A field representing the start and end code unit offsets.

### Attributes

encoding [R]

The associated encoding for the code units.

repository [R]

A pointer to the repository object that is used for lazily creating a code units cache.

### Public Class Methods

new (repository, encoding)
Source

    # File lib/prism/relocation.rb, line 238
    def initialize(repository, encoding)
      @repository = repository
      @encoding = encoding
      @cache = nil
    end

Initialize a new field with the associated repository and encoding.

### Public Instance Methods

fields (value)
Source

    # File lib/prism/relocation.rb, line 246
    def fields(value)
      {
        start_code_units_offset: value.cached_start_code_units_offset(cache),
        end_code_units_offset: value.cached_end_code_units_offset(cache)
      }
    end

Fetches the start and end code units offset of a value for a particular encoding.

### Private Instance Methods

cache ()
Source

    # File lib/prism/relocation.rb, line 256
    def cache
      @cache ||= repository.code_units_cache(encoding)
    end

Lazily create a code units cache for the associated encoding.