Class: Red::AssignmentNode::Operator::Dot

Inherits:
Red::AssignmentNode::Operator show all
Defined in:
lib/red/nodes/assignment_nodes.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from String

#%, #*, #+, #<<, #<=>, #==, #=~, #[], #[]=, #capitalize, #capitalize!, #casecmp, #center, #chomp, #chomp!, #chop, #chop!, #concat, #count, #crypt, #delete, #delete!, #downcase, #downcase!, #each, #each_byte, #each_line, #empty?, #eql?, #gsub, #gsub!, #hash, #hex, #include?, #index, #insert, #inspect, #intern, #length, #ljust, #lstrip, #lstrip!, #match, #next, #next!, #oct, #replace, #reverse, #reverse!, #rindex, #rjust, #rstrip, #rstrip!, #scan, #size, #slice, #slice!, #split, #squeeze, #strip, #strip!, #strip_scripts, #sub, #sub!, #succ, #succ!, #sum, #swapcase, #swapcase!, #to_f, #to_i, #to_s, #to_str, #to_sym, #tr, #tr!, #tr_s, #tr_s!, #upcase, #upcase!, #upto

Constructor Details

#initialize(receiver_sexp, writer_sexp, method_sexp, expression_sexp, options) ⇒ Dot

:op_asgn_2, expression, :foo=, :+ | :* |…, expression

> from e.g. “foo.bar ||= 1”



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/red/nodes/assignment_nodes.rb', line 97

def initialize(receiver_sexp, writer_sexp, method_sexp, expression_sexp, options)
  receiver   = receiver_sexp.red!(:as_receiver => true)
  reader     = writer_sexp.to_s.gsub(/=/,'').to_sym.red!
  writer     = writer_sexp.red!
  method     = (METHOD_ESCAPE[method_sexp] || method_sexp).red!
  expression = expression_sexp.red!(:as_argument => true)
  object     = "%s.m$%s()" % [receiver, reader]
  unless string = ((method == '||' && LogicNode::Conjunction::Or.string) || (method == '&&' && LogicNode::Conjunction::And.string))
    operation = "%s.m$%s(%s)" % [object, method, expression]
  else
    operation = string % [object, expression]
  end
  self << "%s.m$%s(%s)" % [receiver, writer, operation]
end