public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
require 'rjb'
 
Rjb::load(classpath = 'jrubyparser-0.2.jar', jvmargs=[])
 
module ToSource
SR = Rjb::import('java.io.StringReader')
PC = Rjb::import('org.jrubyparser.parser.ParserConfiguration')
P = Rjb::import('org.jrubyparser.Parser')
RWV = Rjb::import('org.jrubyparser.rewriter.ReWriteVisitor')
SW = Rjb::import('java.io.StringWriter')
end
 
class String
def to_ast
ToSource::P.new.parse('(string)', ToSource::SR.new(self), ToSource::PC.new)
end
end
 
class Rjb::Rjb_JavaProxy
def to_s
toString
end
end
 
''.to_ast.class.class_eval do
def to_source
sw = ToSource::SW.new
rwv = ToSource::RWV.new(sw, '(string)')
accept(rwv)
sw.toString
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.