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.
11152 11153 11154 11155 11156 |
# File 'lib/syntax_tree.rb', line 11152 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
11150 11151 11152 |
# File 'lib/syntax_tree.rb', line 11150 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11147 11148 11149 |
# File 'lib/syntax_tree.rb', line 11147 def location @location end |
#variable ⇒ Object (readonly)
- Backref | VarRef
-
the variable being interpolated
11144 11145 11146 |
# File 'lib/syntax_tree.rb', line 11144 def variable @variable end |
Instance Method Details
#child_nodes ⇒ Object
11158 11159 11160 |
# File 'lib/syntax_tree.rb', line 11158 def child_nodes [variable] end |
#format(q) ⇒ Object
11162 11163 11164 11165 11166 |
# File 'lib/syntax_tree.rb', line 11162 def format(q) q.text('#{') q.format(variable) q.text("}") end |
#pretty_print(q) ⇒ Object
11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 |
# File 'lib/syntax_tree.rb', line 11168 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
11179 11180 11181 11182 11183 11184 11185 11186 |
# File 'lib/syntax_tree.rb', line 11179 def to_json(*opts) { type: :string_dvar, var: variable, loc: location, cmts: comments }.to_json(*opts) end |