Class: Sexp2Ruby::Node::Rescue
- Defined in:
- lib/sexp2ruby/node/rescue.rb
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
Methods inherited from Base
Constructor Details
This class inherits a constructor from Sexp2Ruby::Node::Base
Instance Method Details
#to_s(exp) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sexp2ruby/node/rescue.rb', line 4 def to_s(exp) body = process(exp.shift) unless exp.first.first == :resbody els = process(exp.pop) unless exp.last.first == :resbody body ||= "# do nothing" simple = exp.size == 1 && exp.resbody.size <= 3 && !exp.resbody.block && !exp.resbody.return resbodies = [] until exp.empty? do resbody = exp.shift simple &&= resbody[1] == s(:array) simple &&= resbody[2] != nil && resbody[2].node_type != :block resbodies << process(resbody) end if els "#{indent body}\n#{resbodies.join(LF)}\nelse\n#{indent els}" elsif simple resbody = resbodies.first.sub(/\n\s*/, ' ') "#{body} #{resbody}" else "#{indent body}\n#{resbodies.join(LF)}" end end |