Class: SyntaxTree::ConstPathRef
Overview
ConstPathRef represents referencing a constant by a path.
object::Const
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: []) ⇒ ConstPathRef
constructor
A new instance of ConstPathRef.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(parent:, constant:, location:, comments: []) ⇒ ConstPathRef
Returns a new instance of ConstPathRef.
3535 3536 3537 3538 3539 3540 |
# File 'lib/syntax_tree/node.rb', line 3535 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
3533 3534 3535 |
# File 'lib/syntax_tree/node.rb', line 3533 def comments @comments end |
#constant ⇒ Object (readonly)
- Const
-
the constant itself
3530 3531 3532 |
# File 'lib/syntax_tree/node.rb', line 3530 def constant @constant end |
#parent ⇒ Object (readonly)
- untyped
-
the source of the constant
3527 3528 3529 |
# File 'lib/syntax_tree/node.rb', line 3527 def parent @parent end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3542 3543 3544 |
# File 'lib/syntax_tree/node.rb', line 3542 def child_nodes [parent, constant] end |
#deconstruct_keys(keys) ⇒ Object
3548 3549 3550 3551 3552 3553 3554 3555 |
# File 'lib/syntax_tree/node.rb', line 3548 def deconstruct_keys(keys) { parent: parent, constant: constant, location: location, comments: comments } end |
#format(q) ⇒ Object
3557 3558 3559 3560 3561 |
# File 'lib/syntax_tree/node.rb', line 3557 def format(q) q.format(parent) q.text("::") q.format(constant) end |
#pretty_print(q) ⇒ Object
3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 |
# File 'lib/syntax_tree/node.rb', line 3563 def pretty_print(q) q.group(2, "(", ")") do q.text("const_path_ref") q.breakable q.pp(parent) q.breakable q.pp(constant) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
3577 3578 3579 3580 3581 3582 3583 3584 3585 |
# File 'lib/syntax_tree/node.rb', line 3577 def to_json(*opts) { type: :const_path_ref, parent: parent, constant: constant, loc: location, cmts: comments }.to_json(*opts) end |