Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

RubyVM::AbstractSyntaxTree.parse

RubyVM::AbstractSyntaxTree.parse(string) → RubyVM::AbstractSyntaxTree::Node

Parses the given string into an abstract syntax tree, returning the root node of that tree.

SyntaxError is raised if the given string is invalid syntax.

Example
RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
# => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-1:9>
See also .of .parse_file also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0