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.
1061 1062 1063 1064 1065 1066 |
# File 'lib/syntax_tree/node.rb', line 1061 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
1059 1060 1061 |
# File 'lib/syntax_tree/node.rb', line 1059 def comments @comments end |
#target ⇒ Object (readonly)
- ARefField | ConstPathField | Field | TopConstField | VarField
-
the target
to assign the result of the expression to
1053 1054 1055 |
# File 'lib/syntax_tree/node.rb', line 1053 def target @target end |
#value ⇒ Object (readonly)
- untyped
-
the expression to be assigned
1056 1057 1058 |
# File 'lib/syntax_tree/node.rb', line 1056 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
1068 1069 1070 |
# File 'lib/syntax_tree/node.rb', line 1068 def accept(visitor) visitor.visit_assign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
1072 1073 1074 |
# File 'lib/syntax_tree/node.rb', line 1072 def child_nodes [target, value] end |
#deconstruct_keys(keys) ⇒ Object
1078 1079 1080 |
# File 'lib/syntax_tree/node.rb', line 1078 def deconstruct_keys(keys) { target: target, value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 |
# File 'lib/syntax_tree/node.rb', line 1082 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 |