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.
-
#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 (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ 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.
9630 9631 9632 9633 9634 |
# File 'lib/syntax_tree/node.rb', line 9630 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
9628 9629 9630 |
# File 'lib/syntax_tree/node.rb', line 9628 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
9625 9626 9627 |
# File 'lib/syntax_tree/node.rb', line 9625 def location @location end |
#variable ⇒ Object (readonly)
- Backref | VarRef
-
the variable being interpolated
9622 9623 9624 |
# File 'lib/syntax_tree/node.rb', line 9622 def variable @variable end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
9636 9637 9638 |
# File 'lib/syntax_tree/node.rb', line 9636 def child_nodes [variable] end |
#deconstruct_keys(keys) ⇒ Object
9642 9643 9644 |
# File 'lib/syntax_tree/node.rb', line 9642 def deconstruct_keys(keys) { variable: variable, location: location, comments: comments } end |
#format(q) ⇒ Object
9646 9647 9648 9649 9650 |
# File 'lib/syntax_tree/node.rb', line 9646 def format(q) q.text('#{') q.format(variable) q.text("}") end |
#pretty_print(q) ⇒ Object
9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 |
# File 'lib/syntax_tree/node.rb', line 9652 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
9663 9664 9665 9666 9667 9668 9669 9670 |
# File 'lib/syntax_tree/node.rb', line 9663 def to_json(*opts) { type: :string_dvar, var: variable, loc: location, cmts: comments }.to_json(*opts) end |