lib/ruby2ruby.rb in ruby2ruby-2.0.0.b1 vs lib/ruby2ruby.rb in ruby2ruby-2.0.0
- old
+ new
@@ -22,11 +22,11 @@
}
end
end
class Ruby2Ruby < SexpProcessor
- VERSION = '2.0.0.b1'
+ VERSION = '2.0.0'
LINE_LENGTH = 78
BINARY = [:<=>, :==, :<, :>, :<=, :>=, :-, :+, :*, :/, :%, :<<, :>>, :**]
##
@@ -86,30 +86,23 @@
until exp.empty? do
arg = exp.shift
case arg
when Symbol then
args << arg
- when Array then
+ when Sexp then
case arg.first
- when :block then
- asgns = {}
- arg[1..-1].each do |lasgn|
- asgns[lasgn[1]] = process(lasgn)
- end
-
- args.each_with_index do |name, index|
- args[index] = asgns[name] if asgns.has_key? name
- end
+ when :lasgn then
+ args << process(arg)
else
raise "unknown arg type #{arg.first.inspect}"
end
else
raise "unknown arg type #{arg.inspect}"
end
end
- return "(#{args.join ', '})"
+ "(#{args.join ', '})"
end
def process_array(exp)
"[#{process_arglist(exp)}]"
end
@@ -334,11 +327,11 @@
end
end
comm = exp.comments
name = exp.shift
- args = process(exp.shift)
+ args = process exp.shift
args = "" if args == "()"
exp.shift if exp == s(s(:nil)) # empty it out of a default nil expression
body = []
@@ -511,13 +504,21 @@
end
def process_iter(exp)
iter = process exp.shift
args = exp.shift
- args = (args == 0) ? '' : process(args)
body = exp.empty? ? nil : process(exp.shift)
+ args = case args
+ when 0 then
+ " ||"
+ else
+ a = process(args)[1..-2]
+ a = " |#{a}|" unless a.empty?
+ a
+ end
+
b, e = if iter == "END" then
[ "{", "}" ]
else
[ "do", "end" ]
end
@@ -525,11 +526,11 @@
iter.sub!(/\(\)$/, '')
# REFACTOR: ugh
result = []
result << "#{iter} {"
- result << " |#{args}|" if args
+ result << args
if body then
result << " #{body.strip} "
else
result << ' '
end
@@ -537,10 +538,10 @@
result = result.join
return result if result !~ /\n/ and result.size < LINE_LENGTH
result = []
result << "#{iter} #{b}"
- result << " |#{args}|" if args
+ result << args
result << "\n"
if body then
result << indent(body.strip)
result << "\n"
end