Class: SyntaxTree::GVar
- Inherits:
-
Object
- Object
- SyntaxTree::GVar
- Defined in:
- lib/syntax_tree.rb
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
- #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.
6262 6263 6264 6265 6266 |
# File 'lib/syntax_tree.rb', line 6262 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
6260 6261 6262 |
# File 'lib/syntax_tree.rb', line 6260 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
6257 6258 6259 |
# File 'lib/syntax_tree.rb', line 6257 def location @location end |
#value ⇒ Object (readonly)
- String
-
the name of the global variable
6254 6255 6256 |
# File 'lib/syntax_tree.rb', line 6254 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
6268 6269 6270 |
# File 'lib/syntax_tree.rb', line 6268 def child_nodes [] end |
#format(q) ⇒ Object
6272 6273 6274 |
# File 'lib/syntax_tree.rb', line 6272 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 |
# File 'lib/syntax_tree.rb', line 6276 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
6287 6288 6289 6290 6291 |
# File 'lib/syntax_tree.rb', line 6287 def to_json(*opts) { type: :gvar, value: value, loc: location, cmts: comments }.to_json( *opts ) end |