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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the name of the global variable.
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.
5469 5470 5471 5472 5473 |
# File 'lib/syntax_tree/node.rb', line 5469 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
5467 5468 5469 |
# File 'lib/syntax_tree/node.rb', line 5467 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5464 5465 5466 |
# File 'lib/syntax_tree/node.rb', line 5464 def location @location end |
#value ⇒ Object (readonly)
- String
-
the name of the global variable
5461 5462 5463 |
# File 'lib/syntax_tree/node.rb', line 5461 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
5475 5476 5477 |
# File 'lib/syntax_tree/node.rb', line 5475 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
5481 5482 5483 |
# File 'lib/syntax_tree/node.rb', line 5481 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
5485 5486 5487 |
# File 'lib/syntax_tree/node.rb', line 5485 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 |
# File 'lib/syntax_tree/node.rb', line 5489 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
5500 5501 5502 5503 5504 |
# File 'lib/syntax_tree/node.rb', line 5500 def to_json(*opts) { type: :gvar, value: value, loc: location, cmts: comments }.to_json( *opts ) end |