RubyVM::AbstractSyntaxTree::Node
instances are created by parse methods in RubyVM::AbstractSyntaxTree
.
This class is MRI specific.
Instance Methods
ast.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/ast.rb, line 131
def children
__builtin_ast_node_children
end
Returns AST nodes under this one. Each kind of node has different children, depending on what kind of node it is.
The returned array may contain other nodes or nil
.
ast.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/ast.rb, line 104
def first_column
__builtin_ast_node_first_column
end
The column number in the source code where this AST’s text began.
ast.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/ast.rb, line 96
def first_lineno
__builtin_ast_node_first_lineno
end
The line number in the source code where this AST’s text began.
ast.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/ast.rb, line 139
def inspect
__builtin_ast_node_inspect
end
Returns debugging information about this node as a string.
ast.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/ast.rb, line 120
def last_column
__builtin_ast_node_last_column
end
The column number in the source code where this AST’s text ended.
ast.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/ast.rb, line 112
def last_lineno
__builtin_ast_node_last_lineno
end
The line number in the source code where this AST’s text ended.
lib/pp.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/pp.rb, line 542
def pretty_print(q)
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
case type
when :SCOPE
pretty_print_children(q, %w"tbl args body")
when :ARGS
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
when :DEFN
pretty_print_children(q, %w[mid body])
when :ARYPTN
pretty_print_children(q, %w[const pre rest post])
when :HSHPTN
pretty_print_children(q, %w[const kw kwrest])
else
pretty_print_children(q)
end
}
end
No documentation available
lib/pp.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/lib/pp.rb, line 529
def pretty_print_children(q, names = [])
children.zip(names) do |c, n|
if n
q.breakable
q.text "#{n}:"
end
q.group(2) do
q.breakable
q.pp c
end
end
end
No documentation available
ast.rb
View on GitHub
# File tmp/rubies/ruby-2.7.6/ast.rb, line 88
def type
__builtin_ast_node_type
end
Returns the type of this node as a symbol.
root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2") root.type # => :SCOPE call = root.children[2] call.type # => :OPCALL