Class: Sexp2Ruby::Node::Attrasgn

Inherits:
Base
  • Object
show all
Defined in:
lib/sexp2ruby/node/attrasgn.rb

Constant Summary

Constants inherited from Base

Base::ASSIGN_NODES, Base::LF, Base::LINE_LENGTH

Instance Attribute Summary

Attributes inherited from Base

#processor

Instance Method Summary collapse

Methods inherited from Base

#initialize

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
# File 'lib/sexp2ruby/node/attrasgn.rb', line 4

def to_s(exp)
  receiver = process exp.shift
  name = exp.shift
  rhs  = exp.pop
  args = s(:array, *exp)
  exp.clear

  case name
  when :[]= then
    args = process args
    "#{receiver}#{args} = #{process rhs}"
  else
    raise "dunno what to do: #{args.inspect}" unless args.size == 1 # s(:array)
    name = name.to_s.sub(/=$/, '')
    if rhs && rhs != s(:arglist)
      "#{receiver}.#{name} = #{process(rhs)}"
    else
      raise "dunno what to do: #{rhs.inspect}"
    end
  end
end