ruby-ast-explorer

AST Explorer lets you to visualize your ruby code as AST(Abstract Syntax Trees).

This uses the parser gem to convert the source code into ASTs and the TreeWriter class of the gem to apply transformations on the AST nodes and convert them back to source code.

We can take the transformation logic and put into a ruby file like transform.rb and use the same to do large scale refactorings with your ruby code base using tools like codeshift and cybertron.

$ codeshift -t transform.rb app/models/**/*.rb

Export as gist

You can also export the source and transform code as gist to your Github account by clicking the Export as gist button. But before that you need to sign in with Github and give permission to create gists for this app named ruby-ast-explorer.

And with that you can directly use the transform from your gist.

$ codeshift -t https://gist.githubusercontent.com/[user]/.../transform.rb  app/models/**/*.rb

It has got four panes with the following content:

  • Top-Left => Original Source Code
  • Top-Right => AST in Tree and S-expressions formats
  • Bottom-Left => Transform Class
  • Bottom-Right => Output

screenshot

Reference:

Inspired by AST Explorer by Felix Kling

Tools

Other related tools