Class: SyntaxTree::StringDVar
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.
-
#variable ⇒ Object
readonly
- Backref | VarRef
-
the variable being interpolated.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(variable:, location:, comments: []) ⇒ StringDVar
constructor
A new instance of StringDVar.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(variable:, location:, comments: []) ⇒ StringDVar
Returns a new instance of StringDVar.
8172 8173 8174 8175 8176 |
# File 'lib/syntax_tree/node.rb', line 8172 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
8170 8171 8172 |
# File 'lib/syntax_tree/node.rb', line 8170 def comments @comments end |
#variable ⇒ Object (readonly)
- Backref | VarRef
-
the variable being interpolated
8167 8168 8169 |
# File 'lib/syntax_tree/node.rb', line 8167 def variable @variable end |
Instance Method Details
#accept(visitor) ⇒ Object
8178 8179 8180 |
# File 'lib/syntax_tree/node.rb', line 8178 def accept(visitor) visitor.visit_string_dvar(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8182 8183 8184 |
# File 'lib/syntax_tree/node.rb', line 8182 def child_nodes [variable] end |
#deconstruct_keys(_keys) ⇒ Object
8188 8189 8190 |
# File 'lib/syntax_tree/node.rb', line 8188 def deconstruct_keys(_keys) { variable: variable, location: location, comments: comments } end |
#format(q) ⇒ Object
8192 8193 8194 8195 8196 |
# File 'lib/syntax_tree/node.rb', line 8192 def format(q) q.text('#{') q.format(variable) q.text("}") end |