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.
10612 10613 10614 10615 10616 |
# File 'lib/syntax_tree.rb', line 10612 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
10610 10611 10612 |
# File 'lib/syntax_tree.rb', line 10610 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10607 10608 10609 |
# File 'lib/syntax_tree.rb', line 10607 def location @location end |
#variable ⇒ Object (readonly)
- Backref | VarRef
-
the variable being interpolated
10604 10605 10606 |
# File 'lib/syntax_tree.rb', line 10604 def variable @variable end |
Instance Method Details
#child_nodes ⇒ Object
10618 10619 10620 |
# File 'lib/syntax_tree.rb', line 10618 def child_nodes [variable] end |
#format(q) ⇒ Object
10622 10623 10624 10625 10626 |
# File 'lib/syntax_tree.rb', line 10622 def format(q) q.text('#{') q.format(variable) q.text("}") end |
#pretty_print(q) ⇒ Object
10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 |
# File 'lib/syntax_tree.rb', line 10628 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
10639 10640 10641 10642 10643 10644 10645 10646 |
# File 'lib/syntax_tree.rb', line 10639 def to_json(*opts) { type: :string_dvar, var: variable, loc: location, cmts: comments }.to_json(*opts) end |