Class: SyntaxTree::StringDVar
- Inherits:
-
Object
- Object
- SyntaxTree::StringDVar
- Defined in:
- lib/syntax_tree.rb
Overview
StringDVar represents shorthand interpolation of a variable into a string. It allows you to take an instance variable, class variable, or global variable and omit the braces when interpolating.
"#@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.
-
#variable ⇒ Object
readonly
- Backref | VarRef
-
the variable being interpolated.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(variable:, location:, comments: []) ⇒ StringDVar
constructor
A new instance of StringDVar.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(variable:, location:, comments: []) ⇒ StringDVar
Returns a new instance of StringDVar.
11284 11285 11286 11287 11288 |
# File 'lib/syntax_tree.rb', line 11284 def initialize(variable:, location:, comments: []) @variable = variable @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11282 11283 11284 |
# File 'lib/syntax_tree.rb', line 11282 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11279 11280 11281 |
# File 'lib/syntax_tree.rb', line 11279 def location @location end |
#variable ⇒ Object (readonly)
- Backref | VarRef
-
the variable being interpolated
11276 11277 11278 |
# File 'lib/syntax_tree.rb', line 11276 def variable @variable end |
Instance Method Details
#child_nodes ⇒ Object
11290 11291 11292 |
# File 'lib/syntax_tree.rb', line 11290 def child_nodes [variable] end |
#format(q) ⇒ Object
11294 11295 11296 11297 11298 |
# File 'lib/syntax_tree.rb', line 11294 def format(q) q.text('#{') q.format(variable) q.text("}") end |
#pretty_print(q) ⇒ Object
11300 11301 11302 11303 11304 11305 11306 11307 11308 11309 |
# File 'lib/syntax_tree.rb', line 11300 def pretty_print(q) q.group(2, "(", ")") do q.text("string_dvar") q.breakable q.pp(variable) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
11311 11312 11313 11314 11315 11316 11317 11318 |
# File 'lib/syntax_tree.rb', line 11311 def to_json(*opts) { type: :string_dvar, var: variable, loc: location, cmts: comments }.to_json(*opts) end |