Class: Prism::Relocation::CodeUnitOffsetsField

Inherits:
Object
  • Object
show all
Defined in:
lib/prism/relocation.rb

Overview

A field representing the start and end code unit offsets.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, encoding) ⇒ CodeUnitOffsetsField

Initialize a new field with the associated repository and encoding.



238
239
240
241
242
# File 'lib/prism/relocation.rb', line 238

def initialize(repository, encoding)
  @repository = repository
  @encoding = encoding
  @cache = nil
end

Instance Attribute Details

#encodingObject (readonly)

The associated encoding for the code units.



235
236
237
# File 'lib/prism/relocation.rb', line 235

def encoding
  @encoding
end

#repositoryObject (readonly)

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



232
233
234
# File 'lib/prism/relocation.rb', line 232

def repository
  @repository
end

Instance Method Details

#fields(value) ⇒ Object

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



246
247
248
249
250
251
# 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