Class: SyntaxTree::Assign
Overview
Assign represents assigning something to a variable or constant. Generally, the left side of the assignment is going to be any node that ends with the name “Field”.
variable = value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#target ⇒ Object
readonly
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target to assign the result of the expression to.
-
#value ⇒ Object
readonly
- untyped
-
the expression to be assigned.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(target:, value:, location:, comments: []) ⇒ Assign
constructor
A new instance of Assign.
Methods inherited from Node
Constructor Details
#initialize(target:, value:, location:, comments: []) ⇒ Assign
Returns a new instance of Assign.
1109 1110 1111 1112 1113 1114 |
# File 'lib/syntax_tree/node.rb', line 1109 def initialize(target:, value:, location:, comments: []) @target = target @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1107 1108 1109 |
# File 'lib/syntax_tree/node.rb', line 1107 def comments @comments end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
1101 1102 1103 |
# File 'lib/syntax_tree/node.rb', line 1101 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
1104 1105 1106 |
# File 'lib/syntax_tree/node.rb', line 1104 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
1116 1117 1118 |
# File 'lib/syntax_tree/node.rb', line 1116 def accept(visitor) visitor.visit_assign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1120 1121 1122 |
# File 'lib/syntax_tree/node.rb', line 1120 def child_nodes [target, value] end |
#deconstruct_keys(keys) ⇒ Object
1126 1127 1128 |
# File 'lib/syntax_tree/node.rb', line 1126 def deconstruct_keys(keys) { target: target, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 |
# File 'lib/syntax_tree/node.rb', line 1130 def format(q) q.group do q.format(target) q.text(" =") if skip_indent? q.text(" ") q.format(value) else q.indent do q.breakable q.format(value) end end end end |