Class: SyntaxTree::RAssign
- Inherits:
-
Object
- Object
- SyntaxTree::RAssign
- Defined in:
- lib/syntax_tree.rb
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#operator ⇒ Object
readonly
- Kw | Op
-
the operator being used to match against the pattern, which is either => or in.
-
#pattern ⇒ Object
readonly
- untyped
-
the pattern on the right-hand side of the expression.
-
#value ⇒ Object
readonly
- untyped
-
the left-hand expression.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, operator:, pattern:, location:, comments: []) ⇒ RAssign
constructor
A new instance of RAssign.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, operator:, pattern:, location:, comments: []) ⇒ RAssign
3394 3395 3396 3397 3398 3399 3400 |
# File 'lib/syntax_tree.rb', line 3394 def initialize(value:, operator:, pattern:, location:, comments: []) @value = value @operator = operator @pattern = pattern @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3392 3393 3394 |
# File 'lib/syntax_tree.rb', line 3392 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3389 3390 3391 |
# File 'lib/syntax_tree.rb', line 3389 def location @location end |
#operator ⇒ Object (readonly)
- Kw | Op
-
the operator being used to match against the pattern, which is
either => or in
3383 3384 3385 |
# File 'lib/syntax_tree.rb', line 3383 def operator @operator end |
#pattern ⇒ Object (readonly)
- untyped
-
the pattern on the right-hand side of the expression
3386 3387 3388 |
# File 'lib/syntax_tree.rb', line 3386 def pattern @pattern end |
#value ⇒ Object (readonly)
- untyped
-
the left-hand expression
3379 3380 3381 |
# File 'lib/syntax_tree.rb', line 3379 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
3402 3403 3404 |
# File 'lib/syntax_tree.rb', line 3402 def child_nodes [value, operator, pattern] end |
#format(q) ⇒ Object
3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 |
# File 'lib/syntax_tree.rb', line 3406 def format(q) q.group do q.format(value) q.text(" ") q.format(operator) q.group do q.indent do q.breakable q.format(pattern) end end end end |
#pretty_print(q) ⇒ Object
3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 |
# File 'lib/syntax_tree.rb', line 3420 def pretty_print(q) q.group(2, "(", ")") do q.text("rassign") q.breakable q.pp(value) q.breakable q.pp(operator) q.breakable q.pp(pattern) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 |
# File 'lib/syntax_tree.rb', line 3437 def to_json(*opts) { type: :rassign, value: value, op: operator, pattern: pattern, loc: location, cmts: comments }.to_json(*opts) end |