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.
-
#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: []) ⇒ 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.
10155 10156 10157 10158 10159 |
# File 'lib/syntax_tree/node.rb', line 10155 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
10153 10154 10155 |
# File 'lib/syntax_tree/node.rb', line 10153 def comments @comments end |
#constant ⇒ Object (readonly)
- Const
-
the constant being assigned
10147 10148 10149 |
# File 'lib/syntax_tree/node.rb', line 10147 def constant @constant end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10150 10151 10152 |
# File 'lib/syntax_tree/node.rb', line 10150 def location @location end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10161 10162 10163 |
# File 'lib/syntax_tree/node.rb', line 10161 def child_nodes [constant] end |
#deconstruct_keys(keys) ⇒ Object
10167 10168 10169 |
# File 'lib/syntax_tree/node.rb', line 10167 def deconstruct_keys(keys) { constant: constant, location: location, comments: comments } end |
#format(q) ⇒ Object
10171 10172 10173 10174 |
# File 'lib/syntax_tree/node.rb', line 10171 def format(q) q.text("::") q.format(constant) end |
#pretty_print(q) ⇒ Object
10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 |
# File 'lib/syntax_tree/node.rb', line 10176 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
10187 10188 10189 10190 10191 10192 10193 10194 |
# File 'lib/syntax_tree/node.rb', line 10187 def to_json(*opts) { type: :top_const_field, constant: constant, loc: location, cmts: comments }.to_json(*opts) end |