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
11076 11077 11078 11079 11080 |
# File 'lib/syntax_tree.rb', line 11076 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
11074 11075 11076 |
# File 'lib/syntax_tree.rb', line 11074 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11071 11072 11073 |
# File 'lib/syntax_tree.rb', line 11071 def location @location end |
#variable ⇒ Object (readonly)
- Backref | VarRef
-
the variable being interpolated
11068 11069 11070 |
# File 'lib/syntax_tree.rb', line 11068 def variable @variable end |
Instance Method Details
#child_nodes ⇒ Object
11082 11083 11084 |
# File 'lib/syntax_tree.rb', line 11082 def child_nodes [variable] end |
#format(q) ⇒ Object
11086 11087 11088 11089 11090 |
# File 'lib/syntax_tree.rb', line 11086 def format(q) q.text('#{') q.format(variable) q.text("}") end |
#pretty_print(q) ⇒ Object
11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 |
# File 'lib/syntax_tree.rb', line 11092 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
11103 11104 11105 11106 11107 11108 11109 11110 |
# File 'lib/syntax_tree.rb', line 11103 def to_json(*opts) { type: :string_dvar, var: variable, loc: location, cmts: comments }.to_json(*opts) end |