Class: SyntaxTree::StringDVar
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::StringDVar
show all
- Defined in:
- lib/syntax_tree/node.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
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(variable:, location:) ⇒ StringDVar
Returns a new instance of StringDVar.
10213
10214
10215
10216
10217
|
# File 'lib/syntax_tree/node.rb', line 10213
def initialize(variable:, location:)
@variable = variable
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10211
10212
10213
|
# File 'lib/syntax_tree/node.rb', line 10211
def
@comments
end
|
#variable ⇒ Object
- Backref | VarRef
-
the variable being interpolated
10208
10209
10210
|
# File 'lib/syntax_tree/node.rb', line 10208
def variable
@variable
end
|
Instance Method Details
#===(other) ⇒ Object
10250
10251
10252
|
# File 'lib/syntax_tree/node.rb', line 10250
def ===(other)
other.is_a?(StringDVar) && variable === other.variable
end
|
#accept(visitor) ⇒ Object
10219
10220
10221
|
# File 'lib/syntax_tree/node.rb', line 10219
def accept(visitor)
visitor.visit_string_dvar(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
10223
10224
10225
|
# File 'lib/syntax_tree/node.rb', line 10223
def child_nodes
[variable]
end
|
#copy(variable: nil, location: nil) ⇒ Object
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
|
# File 'lib/syntax_tree/node.rb', line 10227
def copy(variable: nil, location: nil)
node =
StringDVar.new(
variable: variable || self.variable,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
10240
10241
10242
|
# File 'lib/syntax_tree/node.rb', line 10240
def deconstruct_keys(_keys)
{ variable: variable, location: location, comments: }
end
|
10244
10245
10246
10247
10248
|
# File 'lib/syntax_tree/node.rb', line 10244
def format(q)
q.text('#{')
q.format(variable)
q.text("}")
end
|