Class: SyntaxTree::ConstPathField
- Inherits:
-
Object
- Object
- SyntaxTree::ConstPathField
- Defined in:
- lib/syntax_tree.rb
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
- #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.
4219 4220 4221 4222 4223 4224 |
# File 'lib/syntax_tree.rb', line 4219 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
4217 4218 4219 |
# File 'lib/syntax_tree.rb', line 4217 def comments @comments end |
#constant ⇒ Object (readonly)
- Const
-
the constant itself
4211 4212 4213 |
# File 'lib/syntax_tree.rb', line 4211 def constant @constant end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4214 4215 4216 |
# File 'lib/syntax_tree.rb', line 4214 def location @location end |
#parent ⇒ Object (readonly)
- untyped
-
the source of the constant
4208 4209 4210 |
# File 'lib/syntax_tree.rb', line 4208 def parent @parent end |
Instance Method Details
#child_nodes ⇒ Object
4226 4227 4228 |
# File 'lib/syntax_tree.rb', line 4226 def child_nodes [parent, constant] end |
#format(q) ⇒ Object
4230 4231 4232 4233 4234 |
# File 'lib/syntax_tree.rb', line 4230 def format(q) q.format(parent) q.text("::") q.format(constant) end |
#pretty_print(q) ⇒ Object
4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 |
# File 'lib/syntax_tree.rb', line 4236 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
4250 4251 4252 4253 4254 4255 4256 4257 4258 |
# File 'lib/syntax_tree.rb', line 4250 def to_json(*opts) { type: :const_path_field, parent: parent, constant: constant, loc: location, cmts: comments }.to_json(*opts) end |