Skip to content
Create a gist now

Instantly share code, notes, and snippets.

# 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
class Ruby2Ruby < SexpProcessor
def self.translate(klass_or_str, method = nil)
sexp = ParseTree.translate(klass_or_str, method)
unifier =
unifier.processors.each do |p|
p.unsupported.delete :cfunc # HACK
sexp = unifier.process(sexp)
# The Beef
class Module
def to_ruby

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.

gem install ruby2ruby ParseTree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.