James Coglan
8/20/2008 5:17:00 PM
[Note: parts of this message were removed to make it a legal post.]
One possible stab at it (works on Ubutun, couldn't get it to work on
Windows):
#================================
require 'rubygems'
require 'ruby2ruby'
def serialize_block(&block)
return nil unless block_given?
klass = Class.new
klass.class_eval do
define_method :serializable, &block
end
str = RubyToRuby.translate(klass, :serializable)
str.sub(/^def \S+\(([^\)]*)\)/, 'lambda { |\1|').sub(/end$/, '}')
end
s = serialize_block do |*args|
something do
args.join(', ')
end
end
puts s
#================================
Outputs:
lambda { |*args|
something { args.join(", ") }
}
This won't sort out the closure business, but will at least extract the
source code of a Proc.