Class: Red::AssignmentNode::Operator::Bracket

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, arguments_array_sexp, method_sexp, expression_sexp, options) ⇒ Bracket

:op_asgn_1, expression, [:array, element, element …], :+ | :* |…, expression

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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/red/nodes/assignment_nodes.rb', line 79

def initialize(receiver_sexp, arguments_array_sexp, method_sexp, expression_sexp, options)
  receiver   = receiver_sexp.red!(:as_receiver => true)
  arguments  = arguments_array_sexp[1..-1].map {|argument_sexp| argument_sexp.red!(:as_argument => true) }.join(",")
  comma      = arguments.empty? ? "" : ","
  method     = (METHOD_ESCAPE[method_sexp] || method_sexp).red!
  expression = expression_sexp.red!(:as_argument => true)
  object     = "%s.m$_brac(%s)" % [receiver, arguments]
  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$_breq(%s%s%s)" % [receiver, arguments, comma, operation]
end