c31opg
Last Updated: February 25, 2016
·
622
· sheerun
Photo on 08.01.2013 at 04.15

Get fullblown AST of ruby code without using any gem

This feature is already built in 1.9.3 Std-lib:

require 'ripper'
require 'pp'

Ripper.sexp("def m(a) nil end")

It's going to return:

[:program,
   [[:def,
    [:@ident, "m", [1, 4]],
    [:paren, [:params, [[:@ident, "a", [1, 6]]], nil, nil, nil, nil]],
    [:bodystmt, [[:var_ref, [:@kw, "nil", [1, 9]]]], nil, nil, nil]]]]
Say Thanks
Respond