class Prism::Result

This represents the result of a call to ::parse or ::parse_file. It contains the requested structure, any comments that were encounters, and any errors that were encountered.

Attributes

comments[R]

The list of comments that were encountered during parsing.

data_loc[R]

An optional location that represents the location of the __END__ marker and the rest of the content of the file. This content is loaded into the DATA constant when the file being parsed is the main file being executed.

errors[R]

The list of errors that were generated during parsing.

magic_comments[R]

The list of magic comments that were encountered during parsing.

source[R]

A Source instance that represents the source code that was parsed.

warnings[R]

The list of warnings that were generated during parsing.

Public Class Methods

new(comments, magic_comments, data_loc, errors, warnings, source) click to toggle source

Create a new result object with the given values.

# File prism/parse_result.rb, line 684
def initialize(comments, magic_comments, data_loc, errors, warnings, source)
  @comments = comments
  @magic_comments = magic_comments
  @data_loc = data_loc
  @errors = errors
  @warnings = warnings
  @source = source
end

Public Instance Methods

code_units_cache(encoding) click to toggle source

Create a code units cache for the given encoding.

# File prism/parse_result.rb, line 716
def code_units_cache(encoding)
  source.code_units_cache(encoding)
end
deconstruct_keys(keys) click to toggle source

Implement the hash pattern matching interface for Result.

# File prism/parse_result.rb, line 694
def deconstruct_keys(keys)
  { comments: comments, magic_comments: magic_comments, data_loc: data_loc, errors: errors, warnings: warnings }
end
encoding() click to toggle source

Returns the encoding of the source code that was parsed.

# File prism/parse_result.rb, line 699
def encoding
  source.encoding
end
failure?() click to toggle source

Returns true if there were errors during parsing and false if there were not.

# File prism/parse_result.rb, line 711
def failure?
  !success?
end
success?() click to toggle source

Returns true if there were no errors during parsing and false if there were.

# File prism/parse_result.rb, line 705
def success?
  errors.empty?
end