Skip to content
On this page

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class · Ruby 3.3

SyntaxSuggest::ExplainSyntax

< Object 4 instance methods 1 class methods

Explains syntax errors based on their source

example:

Example
source = "def foo; puts 'lol'" # Note missing end
explain ExplainSyntax.new(
  code_lines: CodeLine.from_source(source)
).call
explain.errors.first
# => "Unmatched keyword, missing `end' ?"

When the error cannot be determined by lexical counting then the parser is run against the input and the raw errors are returned.

Example:

Example
source = "1 * " # Note missing a second number
explain ExplainSyntax.new(
  code_lines: CodeLine.from_source(source)
).call
explain.errors.first
# => "syntax error, unexpected end-of-input"

Class methods 1

Instance methods 4

Constants
No documentation available