Class: SyntaxTree::RAssign
Overview
RAssign represents a single-line pattern match.
value in pattern
value => pattern
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#operator ⇒ Object
readonly
- Kw | Op
-
the operator being used to match against the pattern, which is either => or in.
-
#pattern ⇒ Object
readonly
- Node
-
the pattern on the right-hand side of the expression.
-
#value ⇒ Object
readonly
- Node
-
the left-hand expression.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, operator: nil, pattern: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, operator:, pattern:, location:) ⇒ RAssign
constructor
A new instance of RAssign.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, operator:, pattern:, location:) ⇒ RAssign
Returns a new instance of RAssign.
3215 3216 3217 3218 3219 3220 3221 |
# File 'lib/syntax_tree/node.rb', line 3215 def initialize(value:, operator:, pattern:, location:) @value = value @operator = operator @pattern = pattern @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3213 3214 3215 |
# File 'lib/syntax_tree/node.rb', line 3213 def comments @comments end |
#operator ⇒ Object (readonly)
- Kw | Op
-
the operator being used to match against the pattern, which is
either => or in
3207 3208 3209 |
# File 'lib/syntax_tree/node.rb', line 3207 def operator @operator end |
#pattern ⇒ Object (readonly)
- Node
-
the pattern on the right-hand side of the expression
3210 3211 3212 |
# File 'lib/syntax_tree/node.rb', line 3210 def pattern @pattern end |
#value ⇒ Object (readonly)
- Node
-
the left-hand expression
3203 3204 3205 |
# File 'lib/syntax_tree/node.rb', line 3203 def value @value end |
Instance Method Details
#===(other) ⇒ Object
3277 3278 3279 3280 |
# File 'lib/syntax_tree/node.rb', line 3277 def ===(other) other.is_a?(RAssign) && value === other.value && operator === other.operator && pattern === other.pattern end |
#accept(visitor) ⇒ Object
3223 3224 3225 |
# File 'lib/syntax_tree/node.rb', line 3223 def accept(visitor) visitor.visit_rassign(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3227 3228 3229 |
# File 'lib/syntax_tree/node.rb', line 3227 def child_nodes [value, operator, pattern] end |
#copy(value: nil, operator: nil, pattern: nil, location: nil) ⇒ Object
3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 |
# File 'lib/syntax_tree/node.rb', line 3231 def copy(value: nil, operator: nil, pattern: nil, location: nil) node = RAssign.new( value: value || self.value, operator: operator || self.operator, pattern: pattern || self.pattern, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
3246 3247 3248 3249 3250 3251 3252 3253 3254 |
# File 'lib/syntax_tree/node.rb', line 3246 def deconstruct_keys(_keys) { value: value, operator: operator, pattern: pattern, location: location, comments: comments } end |
#format(q) ⇒ Object
3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 |
# File 'lib/syntax_tree/node.rb', line 3256 def format(q) q.group do q.format(value) q.text(" ") q.format(operator) case pattern when AryPtn, FndPtn, HshPtn q.text(" ") q.format(pattern) else q.group do q.indent do q.breakable_space q.format(pattern) end end end end end |