123456789_123456789_123456789_123456789_123456789_

Class: RubyVM::AbstractSyntaxTree::Node

Relationships & Source Files
Inherits: Object
Defined in: ast.c

Overview

Node instances are created by parse methods in ::RubyVM::AbstractSyntaxTree.

Instance Method Summary

Instance Method Details

#childrenArray

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.

[ GitHub ]

  
# File 'ast.c', line 640

static VALUE
rb_ast_node_children(VALUE self)
{
    struct ASTNodeData *data;
    TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data);

    return node_children(data->ast, data->node);
}

#first_columnInteger

The column number in the source code where this AST’s text began.

[ GitHub ]

  
# File 'ast.c', line 670

static VALUE
rb_ast_node_first_column(VALUE self)
{
    struct ASTNodeData *data;
    TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data);

    return INT2NUM(nd_first_column(data->node));
}

#first_linenoInteger

The line number in the source code where this AST’s text began.

[ GitHub ]

  
# File 'ast.c', line 655

static VALUE
rb_ast_node_first_lineno(VALUE self)
{
    struct ASTNodeData *data;
    TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data);

    return INT2NUM(nd_first_lineno(data->node));
}

#inspectString

Returns debugging information about this node as a string.

[ GitHub ]

  
# File 'ast.c', line 715

static VALUE
rb_ast_node_inspect(VALUE self)
{
    VALUE str;
    VALUE cname;
    struct ASTNodeData *data;
    TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data);

    cname = rb_class_path(rb_obj_class(self));
    str = rb_str_new2("#<");

    rb_str_append(str, cname);
    rb_str_catf(str, ":%s@%d:%d-%d:%d>",
                node_type_to_str(data->node),
                nd_first_lineno(data->node), nd_first_column(data->node),
                nd_last_lineno(data->node), nd_last_column(data->node));

    return str;
}

#last_columnInteger

The column number in the source code where this AST’s text ended.

[ GitHub ]

  
# File 'ast.c', line 700

static VALUE
rb_ast_node_last_column(VALUE self)
{
    struct ASTNodeData *data;
    TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data);

    return INT2NUM(nd_last_column(data->node));
}

#last_linenoInteger

The line number in the source code where this AST’s text ended.

[ GitHub ]

  
# File 'ast.c', line 685

static VALUE
rb_ast_node_last_lineno(VALUE self)
{
    struct ASTNodeData *data;
    TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data);

    return INT2NUM(nd_last_lineno(data->node));
}

#typeSymbol

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
[ GitHub ]

  
# File 'ast.c', line 281

static VALUE
rb_ast_node_type(VALUE self)
{
    struct ASTNodeData *data;
    TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data);

    return rb_sym_intern_ascii_cstr(node_type_to_str(data->node));
}