Class: SyntaxTree::ConstPathField
Overview
ConstPathField represents the child node of some kind of assignment. It represents when you’re assigning to a constant that is being referenced as a child of another variable.
object::Const = value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#constant ⇒ Object
readonly
- Const
-
the constant itself.
-
#parent ⇒ Object
readonly
- untyped
-
the source of the constant.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parent:, constant:, location:, comments: []) ⇒ ConstPathField
constructor
A new instance of ConstPathField.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(parent:, constant:, location:, comments: []) ⇒ ConstPathField
Returns a new instance of ConstPathField.
3468 3469 3470 3471 3472 3473 |
# File 'lib/syntax_tree/node.rb', line 3468 def initialize(parent:, constant:, location:, comments: []) @parent = parent @constant = constant @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3466 3467 3468 |
# File 'lib/syntax_tree/node.rb', line 3466 def comments @comments end |
#constant ⇒ Object (readonly)
- Const
-
the constant itself
3463 3464 3465 |
# File 'lib/syntax_tree/node.rb', line 3463 def constant @constant end |
#parent ⇒ Object (readonly)
- untyped
-
the source of the constant
3460 3461 3462 |
# File 'lib/syntax_tree/node.rb', line 3460 def parent @parent end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3475 3476 3477 |
# File 'lib/syntax_tree/node.rb', line 3475 def child_nodes [parent, constant] end |
#deconstruct_keys(keys) ⇒ Object
3481 3482 3483 3484 3485 3486 3487 3488 |
# File 'lib/syntax_tree/node.rb', line 3481 def deconstruct_keys(keys) { parent: parent, constant: constant, location: location, comments: comments } end |
#format(q) ⇒ Object
3490 3491 3492 3493 3494 |
# File 'lib/syntax_tree/node.rb', line 3490 def format(q) q.format(parent) q.text("::") q.format(constant) end |
#pretty_print(q) ⇒ Object
3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 |
# File 'lib/syntax_tree/node.rb', line 3496 def pretty_print(q) q.group(2, "(", ")") do q.text("const_path_field") q.breakable q.pp(parent) q.breakable q.pp(constant) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
3510 3511 3512 3513 3514 3515 3516 3517 3518 |
# File 'lib/syntax_tree/node.rb', line 3510 def to_json(*opts) { type: :const_path_field, parent: parent, constant: constant, loc: location, cmts: comments }.to_json(*opts) end |