Class: SyntaxTree::TopConstField
Overview
TopConstField is always the child node of some kind of assignment. It represents when you’re assigning to a constant that is being referenced at the top level.
::Constant = value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#constant ⇒ Object
readonly
- Const
-
the constant being assigned.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(constant:, location:, comments: []) ⇒ TopConstField
constructor
A new instance of TopConstField.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(constant:, location:, comments: []) ⇒ TopConstField
Returns a new instance of TopConstField.
9762 9763 9764 9765 9766 |
# File 'lib/syntax_tree/node.rb', line 9762 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
9760 9761 9762 |
# File 'lib/syntax_tree/node.rb', line 9760 def comments @comments end |
#constant ⇒ Object (readonly)
- Const
-
the constant being assigned
9757 9758 9759 |
# File 'lib/syntax_tree/node.rb', line 9757 def constant @constant end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
9768 9769 9770 |
# File 'lib/syntax_tree/node.rb', line 9768 def child_nodes [constant] end |
#deconstruct_keys(keys) ⇒ Object
9774 9775 9776 |
# File 'lib/syntax_tree/node.rb', line 9774 def deconstruct_keys(keys) { constant: constant, location: location, comments: comments } end |
#format(q) ⇒ Object
9778 9779 9780 9781 |
# File 'lib/syntax_tree/node.rb', line 9778 def format(q) q.text("::") q.format(constant) end |
#pretty_print(q) ⇒ Object
9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 |
# File 'lib/syntax_tree/node.rb', line 9783 def pretty_print(q) q.group(2, "(", ")") do q.text("top_const_field") q.breakable q.pp(constant) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
9794 9795 9796 9797 9798 9799 9800 9801 |
# File 'lib/syntax_tree/node.rb', line 9794 def to_json(*opts) { type: :top_const_field, constant: constant, loc: location, cmts: comments }.to_json(*opts) end |