Rephrase - a gem for manipulating Ruby code

Summary

Rephrase converts Ruby procs or methods to source code, allowing you to reformat, reinterpret or otherwise manipulate the generated source code. Possible uses include:

How does it do it?

Rephrase uses the RubyVM::AbstractSyntaxTree API to get the AST of a proc or method. This allows you to manipulate code at runtime, and to be able to access its binding.

How to use it

Use Rephrase.to_source to get the unmodified source code of a proc or method, e.g.:

require 'rephrase'

example = proc { 2 + 2 }
Rephrase.to_source(example) #=> "proc do\n2 + 2\nend"

How to rephrase code

Further documentation is forthcoming…

Limitations