Class: SyntaxTree::GVar
Overview
GVar represents a global variable literal.
$variable
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the name of the global variable.
Attributes inherited from Node
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ GVar
constructor
A new instance of GVar.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ GVar
Returns a new instance of GVar.
5283 5284 5285 5286 5287 |
# File 'lib/syntax_tree/node.rb', line 5283 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
5281 5282 5283 |
# File 'lib/syntax_tree/node.rb', line 5281 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the name of the global variable
5278 5279 5280 |
# File 'lib/syntax_tree/node.rb', line 5278 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
5289 5290 5291 |
# File 'lib/syntax_tree/node.rb', line 5289 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
5295 5296 5297 |
# File 'lib/syntax_tree/node.rb', line 5295 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
5299 5300 5301 |
# File 'lib/syntax_tree/node.rb', line 5299 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 |
# File 'lib/syntax_tree/node.rb', line 5303 def pretty_print(q) q.group(2, "(", ")") do q.text("gvar") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
5314 5315 5316 5317 5318 |
# File 'lib/syntax_tree/node.rb', line 5314 def to_json(*opts) { type: :gvar, value: value, loc: location, cmts: comments }.to_json( *opts ) end |