Method not available on this version
This method is only available on newer versions.
The first available version (v2_6_3) is shown here.
of(p1)
public
Returns AST nodes of
the given proc or method.
RubyVM::AbstractSyntaxTree.of(proc {1 + 2})
def hello
puts "hello, world"
end
RubyVM::AbstractSyntaxTree.of(method(:hello))
static VALUE
rb_ast_s_of(VALUE module, VALUE body)
{
VALUE path, node, lines;
int node_id;
const rb_iseq_t *iseq = NULL;
if (rb_obj_is_proc(body)) {
iseq = vm_proc_iseq(body);
if (!rb_obj_is_iseq((VALUE)iseq)) {
iseq = NULL;
}
}
else {
iseq = rb_method_iseq(body);
}
if (!iseq) return Qnil;
path = rb_iseq_path(iseq);
node_id = iseq->body->location.node_id;
if (!NIL_P(lines = script_lines(path))) {
node = rb_ast_parse_array(lines);
}
else if (RSTRING_LEN(path) == 2 && memcmp(RSTRING_PTR(path), "-e", 2) == 0) {
node = rb_ast_parse_str(rb_e_script);
}
else {
node = rb_ast_parse_file(path);
}
return node_find(node, node_id);
}