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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#parent ⇒ Object
readonly
- untyped
-
the source of the constant.
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.
3579 3580 3581 3582 3583 3584 |
# File 'lib/syntax_tree/node.rb', line 3579 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
3577 3578 3579 |
# File 'lib/syntax_tree/node.rb', line 3577 def comments @comments end |
#constant ⇒ Object (readonly)
- Const
-
the constant itself
3571 3572 3573 |
# File 'lib/syntax_tree/node.rb', line 3571 def constant @constant end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3574 3575 3576 |
# File 'lib/syntax_tree/node.rb', line 3574 def location @location end |
#parent ⇒ Object (readonly)
- untyped
-
the source of the constant
3568 3569 3570 |
# File 'lib/syntax_tree/node.rb', line 3568 def parent @parent end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3586 3587 3588 |
# File 'lib/syntax_tree/node.rb', line 3586 def child_nodes [parent, constant] end |
#deconstruct_keys(keys) ⇒ Object
3592 3593 3594 3595 3596 3597 3598 3599 |
# File 'lib/syntax_tree/node.rb', line 3592 def deconstruct_keys(keys) { parent: parent, constant: constant, location: location, comments: comments } end |
#format(q) ⇒ Object
3601 3602 3603 3604 3605 |
# File 'lib/syntax_tree/node.rb', line 3601 def format(q) q.format(parent) q.text("::") q.format(constant) end |
#pretty_print(q) ⇒ Object
3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 |
# File 'lib/syntax_tree/node.rb', line 3607 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
3621 3622 3623 3624 3625 3626 3627 3628 3629 |
# File 'lib/syntax_tree/node.rb', line 3621 def to_json(*opts) { type: :const_path_field, parent: parent, constant: constant, loc: location, cmts: comments }.to_json(*opts) end |