Permalink
Browse files

Add r2r_show command like parse_tree_show.

[git-p4: depot-paths = "//src/ruby2ruby/dev/": change = 3270]
  • Loading branch information...
1 parent 5563406 commit 51dc44be90a63630a3197b84f5d9629c62e263aa @drbrain drbrain committed Jul 3, 2007
Showing with 45 additions and 0 deletions.
  1. +1 −0 Manifest.txt
  2. +44 −0 bin/r2r_show
View
@@ -2,5 +2,6 @@ History.txt
Manifest.txt
README.txt
Rakefile
+bin/r2r_show
lib/ruby2ruby.rb
test/test_ruby2ruby.rb
View
@@ -0,0 +1,44 @@
+#!/usr/local/bin/ruby -ws
+
+begin require 'rubygems' rescue LoadError end
+require 'ruby2ruby'
+
+def discover_new_classes_from
+ old_classes = []
+ ObjectSpace.each_object(Module) do |klass|
+ old_classes << klass
+ end
+
+ yield
+
+ new_classes = []
+ ObjectSpace.each_object(Module) do |klass|
+ new_classes << klass
+ end
+
+ new_classes -= old_classes
+ new_classes = [ eval($c) ] if defined? $c
+ new_classes
+end
+
+$f = true unless defined? $f
+
+new_classes = discover_new_classes_from do
+ ARGV.unshift "-" if ARGV.empty?
+ ARGV.each do |name|
+ if name == "-" then
+ code = $stdin.read
+ code = "class Example; def example; #{code}; end; end" if $f
+ eval code unless code.nil?
+ else
+ require name
+ end
+ end
+end
+
+result = ParseTree.new.parse_tree(*new_classes)
+
+result = result[0][3][2][1][2..-1] if $f
+
+puts RubyToRuby.new.process(result.first)
+

0 comments on commit 51dc44b

Please sign in to comment.