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]]]]
Written by Adam Stankiewicz
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#