Skip to content

Commit

Permalink
Add public #to_source interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Feb 23, 2012
1 parent f47c9d9 commit 7cb2bd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/to_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@
require "to_source/visitor"

module ToSource
# Public: Converts the node back to its original source code.
#
# Returns the String output.
def to_source
visitor = Visitor.new
lazy_visit(visitor)
visitor.output
end
end

Rubinius::AST::Node.send :include, ToSource
5 changes: 1 addition & 4 deletions test/to_source/visitor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
module ToSource
class VisitorTest < MiniTest::Unit::TestCase
def visit(code)
visitor = Visitor.new
ast = code.to_ast
ast.lazy_visit(visitor)
visitor.output
code.to_ast.to_source
end

def assert_source(code)
Expand Down

0 comments on commit 7cb2bd6

Please sign in to comment.