Class: SyntaxTree::TopConstRef
Overview
TopConstRef is very similar to TopConstField except that it is not involved in an assignment.
::Constant
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#constant ⇒ Object
readonly
- Const
-
the constant being referenced.
-
#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: []) ⇒ TopConstRef
constructor
A new instance of TopConstRef.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(constant:, location:, comments: []) ⇒ TopConstRef
Returns a new instance of TopConstRef.
10212 10213 10214 10215 10216 |
# File 'lib/syntax_tree/node.rb', line 10212 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
10210 10211 10212 |
# File 'lib/syntax_tree/node.rb', line 10210 def comments @comments end |
#constant ⇒ Object (readonly)
- Const
-
the constant being referenced
10204 10205 10206 |
# File 'lib/syntax_tree/node.rb', line 10204 def constant @constant end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10207 10208 10209 |
# File 'lib/syntax_tree/node.rb', line 10207 def location @location end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10218 10219 10220 |
# File 'lib/syntax_tree/node.rb', line 10218 def child_nodes [constant] end |
#deconstruct_keys(keys) ⇒ Object
10224 10225 10226 |
# File 'lib/syntax_tree/node.rb', line 10224 def deconstruct_keys(keys) { constant: constant, location: location, comments: comments } end |
#format(q) ⇒ Object
10228 10229 10230 10231 |
# File 'lib/syntax_tree/node.rb', line 10228 def format(q) q.text("::") q.format(constant) end |
#pretty_print(q) ⇒ Object
10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 |
# File 'lib/syntax_tree/node.rb', line 10233 def pretty_print(q) q.group(2, "(", ")") do q.text("top_const_ref") q.breakable q.pp(constant) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
10244 10245 10246 10247 10248 10249 10250 10251 |
# File 'lib/syntax_tree/node.rb', line 10244 def to_json(*opts) { type: :top_const_ref, constant: constant, loc: location, cmts: comments }.to_json(*opts) end |