Class: SyntaxTree::ConstRef
Overview
ConstRef represents the name of the constant being used in a class or module declaration.
class Container
end
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.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(constant:, location:, comments: []) ⇒ ConstRef
constructor
A new instance of ConstRef.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(constant:, location:, comments: []) ⇒ ConstRef
3718 3719 3720 3721 3722 |
# File 'lib/syntax_tree/node.rb', line 3718 def initialize(constant:, location:, comments: []) @constant = constant @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3716 3717 3718 |
# File 'lib/syntax_tree/node.rb', line 3716 def comments @comments end |
#constant ⇒ Object (readonly)
- Const
-
the constant itself
3710 3711 3712 |
# File 'lib/syntax_tree/node.rb', line 3710 def constant @constant end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
3713 3714 3715 |
# File 'lib/syntax_tree/node.rb', line 3713 def location @location end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
3724 3725 3726 |
# File 'lib/syntax_tree/node.rb', line 3724 def child_nodes [constant] end |
#deconstruct_keys(keys) ⇒ Object
3730 3731 3732 |
# File 'lib/syntax_tree/node.rb', line 3730 def deconstruct_keys(keys) { constant: constant, location: location, comments: comments } end |
#format(q) ⇒ Object
3734 3735 3736 |
# File 'lib/syntax_tree/node.rb', line 3734 def format(q) q.format(constant) end |
#pretty_print(q) ⇒ Object
3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 |
# File 'lib/syntax_tree/node.rb', line 3738 def pretty_print(q) q.group(2, "(", ")") do q.text("const_ref") q.breakable q.pp(constant) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
3749 3750 3751 3752 3753 3754 3755 3756 |
# File 'lib/syntax_tree/node.rb', line 3749 def to_json(*opts) { type: :const_ref, constant: constant, loc: location, cmts: comments }.to_json(*opts) end |