lib/ruby2ruby.rb in ruby2ruby-2.3.0 vs lib/ruby2ruby.rb in ruby2ruby-2.3.1
- old
+ new
@@ -29,11 +29,11 @@
##
# Generate ruby code from a sexp.
class Ruby2Ruby < SexpProcessor
- VERSION = "2.3.0" # :nodoc:
+ VERSION = "2.3.1" # :nodoc:
# cutoff for one-liners
LINE_LENGTH = 78
# binary operation messages
@@ -254,10 +254,12 @@
case name
when *BINARY then
if safe_call
"#{receiver}&.#{name}(#{args.join(', ')})"
+ elsif args.length > 1
+ "#{receiver}.#{name}(#{args.join(', ')})"
else
"(#{receiver} #{name} #{args.join(', ')})"
end
when :[] then
receiver ||= "self"
@@ -732,10 +734,20 @@
def process_nth_ref(exp) # :nodoc:
"$#{exp.shift}"
end
+ def process_op_asgn(exp) # :nodoc:
+ # [[:lvar, :x], [:call, nil, :z, [:lit, 1]], :y, :"||"]
+ lhs = process(exp.shift)
+ rhs = process(exp.shift)
+ index = exp.shift
+ op = exp.shift
+
+ "#{lhs}.#{index} #{op}= #{rhs}"
+ end
+
def process_op_asgn1(exp) # :nodoc:
# [[:lvar, :b], [:arglist, [:lit, 1]], :"||", [:lit, 10]]
lhs = process(exp.shift)
index = process(exp.shift)
msg = exp.shift
@@ -850,9 +862,30 @@
if rhs && rhs != s(:arglist) then
"#{receiver}&.#{name} = #{process(rhs)}"
else
raise "dunno what to do: #{rhs.inspect}"
end
+ end
+
+ def process_safe_op_asgn(exp) # :nodoc:
+ # [[:lvar, :x], [:call, nil, :z, [:lit, 1]], :y, :"||"]
+ lhs = process(exp.shift)
+ rhs = process(exp.shift)
+ index = exp.shift
+ op = exp.shift
+
+ "#{lhs}&.#{index} #{op}= #{rhs}"
+ end
+
+ def process_safe_op_asgn2(exp) # :nodoc:
+ # [[:lvar, :c], :var=, :"||", [:lit, 20]]
+ lhs = process(exp.shift)
+ index = exp.shift.to_s[0..-2]
+ msg = exp.shift
+
+ rhs = process(exp.shift)
+
+ "#{lhs}&.#{index} #{msg}= #{rhs}"
end
def process_sclass(exp) # :nodoc:
"class << #{process(exp.shift)}\n#{indent(process_block(exp))}\nend"
end