Last active
November 5, 2015 18:39
-
-
Save smoll/6b73b1df963076bf3767 to your computer and use it in GitHub Desktop.
Adapted from the unparser usage example, at https://github.com/mbj/unparser#usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'parser/current' | |
require 'unparser' | |
require 'byebug' | |
module YourHelper | |
def s(type, *children) | |
Parser::AST::Node.new(type, children) | |
end | |
end | |
include YourHelper | |
# begin experiments | |
node = s(:def, | |
:foo, | |
s(:args, | |
s(:arg, :x) | |
), | |
s(:send, | |
s(:lvar, :x), | |
:+, | |
s(:int, 3) | |
) | |
) | |
Unparser.unparse(node) # => "def foo(x)\n x + 3\nend" | |
byebug | |
puts "eof" # byebug won't pause execution if it's the last line of code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment