Created
March 3, 2010 21:19
-
-
Save terotil/321038 to your computer and use it in GitHub Desktop.
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
# This is a snippet from my ~/.irbrc | |
# You need to gem install ruby2ruby ParseTree | |
# This is what you do with it | |
# | |
# > class Bar; define_method(:foo) { 'ou hai' }; end | |
# > puts Bar.to_ruby | |
# class Bar < Object | |
# def foo | |
# "ou hai" | |
# end | |
# end | |
require 'ruby2ruby' | |
require 'sexp_processor' | |
require 'unified_ruby' | |
require 'parse_tree' | |
# Monkey-patch to have Ruby2Ruby#translate with r2r >= 1.2.3, from | |
# http://seattlerb.rubyforge.org/svn/ruby2ruby/1.2.2/lib/ruby2ruby.rb | |
class Ruby2Ruby < SexpProcessor | |
def self.translate(klass_or_str, method = nil) | |
sexp = ParseTree.translate(klass_or_str, method) | |
unifier = Unifier.new | |
unifier.processors.each do |p| | |
p.unsupported.delete :cfunc # HACK | |
end | |
sexp = unifier.process(sexp) | |
self.new.process(sexp) | |
end | |
end | |
# The Beef | |
class Module | |
def to_ruby | |
Ruby2Ruby.translate(self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of May 22, 2011 it seems that unified_ruby is merged into the parse_tree project. So you'll have to remove the "require 'unified_ruby'" line. Also to install parse_tree you have to run "gem install ParseTree" rather than using the underscore format.
Edit: Sorry I missed line 2 up top in the comments.