Class: Estreet::AssignmentExpression

Inherits:
Expression show all
Defined in:
lib/estreet/assignment_expression.rb

Instance Attribute Summary

Attributes inherited from Node

#source_location

Instance Method Summary collapse

Methods inherited from Expression

#[], #call, coerce, #property, #to_expression, #to_statement

Methods inherited from Node

#as_json, #loc, #type

Constructor Details

#initialize(left, right, operator = "=") ⇒ AssignmentExpression

Returns a new instance of AssignmentExpression.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/estreet/assignment_expression.rb', line 3

def initialize(left, right, operator="=")
  # TODO: InvalidOperatorError
  Estreet.assert_valid_operator(ASSIGNMENT_OPERATORS, operator)

  @op = operator
  @right = right.to_expression
  @left = if left.respond_to? :to_pattern
    left.to_pattern
  else
    # left.to_expression
    # TODO: Test this!
    Expression.coerce(left)
  end
end

Instance Method Details

#attributesObject



18
19
20
# File 'lib/estreet/assignment_expression.rb', line 18

def attributes
  super.merge(operator: @op, left: @left, right: @right)
end