Class: Sexp2Ruby::Node::Masgn
Constant Summary
Constants inherited from Base
Base::ASSIGN_NODES, Base::LF, Base::LINE_LENGTH
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#to_s(exp) ⇒ Object
s(:masgn, s(:array, s(:lasgn, :var), …), s(:to_ary, <val>, …)) s(:iter, <call>, s(:args, s(:masgn, :a, :b)), <body>).
Methods inherited from Base
Constructor Details
This class inherits a constructor from Sexp2Ruby::Node::Base
Instance Method Details
#to_s(exp) ⇒ Object
s(:masgn, s(:array, s(:lasgn, :var), …), s(:to_ary, <val>, …)) s(:iter, <call>, s(:args, s(:masgn, :a, :b)), <body>)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sexp2ruby/node/masgn.rb', line 7 def to_s(exp) case exp.first when Sexp then lhs = exp.shift rhs = exp.empty? ? nil : exp.shift case lhs.first when :array then lhs.shift # node type lhs = lhs.map do |l| case l.first when :masgn then "(#{process(l)})" else process(l) end end else raise "no clue: #{lhs.inspect}" end if rhs.nil? return lhs.join(", ") else t = rhs.first rhs = process rhs rhs = rhs[1..-2] if t == :array # FIX: bad? I dunno return "#{lhs.join(", ")} = #{rhs}" end when Symbol then # block arg list w/ masgn result = exp.join ", " exp.clear "(#{result})" else raise "unknown masgn: #{exp.inspect}" end end |