Yeah. You can use the Ripper gem (which is included with MRI 1.9) to generate an AST (abstract syntax tree) for a given line of code (via Ripper.sexp ). However, due to architectural changes in MRI 1.9, when your code is parsed and converted to YARV bytecode, the source and AST are discarded and you can no longer get this information. However, if you enter any code that you generated by metaprogramming in Ripper.sexp , you can get the AST for the result. You can also use some of the other tricks shown in JEG2 to parse the source file and create an AST for it (although any metaprogrammed code will not be parsed since it does not exist yet).
source share