Skip to content
to_source is a reverse parser: it transforms Rubinius' AST nodes back to source code.
Find file
New pull request
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

to_source Build Status

to_source is a little Rubinius gem that enables Abstract Syntax Tree nodes to transform themselves into source code. It's the reverse of Rubinius' builtin #to_ast method. See for yourself:

some_code = "a = 123"
ast = some_code.to_ast
# => #<Rubinius::AST::LocalVariableAssignment:0x21b8
        @value=#<Rubinius::AST::FixnumLiteral:0x21bc @value=123 @line=1>
        @variable=nil @line=1 @name=:a>

# => "a = 123"


to_source needs Rubinius 2.0 to run, in either 1.8 or 1.9 mode.

To install it as a gem:

$ gem install to_source

And require 'to_source' from your code. Automatically, your AST nodes respond to the #to_source method.

But if you're using Bundler, just put this in your Gemfile:

gem 'to_source'

And just call #to_source in any AST node!

Who's this

This was made by Josep M. Bach (Txus) under the MIT license. I'm @txustice on twitter (where you should probably follow me!).

Something went wrong with that request. Please try again.