Class: SyntaxTree::StringDVar
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::StringDVar
show all
- Defined in:
- lib/syntax_tree/node.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
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(variable:, location:) ⇒ StringDVar
Returns a new instance of StringDVar.
10057
10058
10059
10060
10061
|
# File 'lib/syntax_tree/node.rb', line 10057
def initialize(variable:, location:)
@variable = variable
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10055
10056
10057
|
# File 'lib/syntax_tree/node.rb', line 10055
def
@comments
end
|
#variable ⇒ Object
- Backref | VarRef
-
the variable being interpolated
10052
10053
10054
|
# File 'lib/syntax_tree/node.rb', line 10052
def variable
@variable
end
|
Instance Method Details
#===(other) ⇒ Object
10094
10095
10096
|
# File 'lib/syntax_tree/node.rb', line 10094
def ===(other)
other.is_a?(StringDVar) && variable === other.variable
end
|
#accept(visitor) ⇒ Object
10063
10064
10065
|
# File 'lib/syntax_tree/node.rb', line 10063
def accept(visitor)
visitor.visit_string_dvar(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
10067
10068
10069
|
# File 'lib/syntax_tree/node.rb', line 10067
def child_nodes
[variable]
end
|
#copy(variable: nil, location: nil) ⇒ Object
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
|
# File 'lib/syntax_tree/node.rb', line 10071
def copy(variable: nil, location: nil)
node =
StringDVar.new(
variable: variable || self.variable,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
10084
10085
10086
|
# File 'lib/syntax_tree/node.rb', line 10084
def deconstruct_keys(_keys)
{ variable: variable, location: location, comments: }
end
|
10088
10089
10090
10091
10092
|
# File 'lib/syntax_tree/node.rb', line 10088
def format(q)
q.text('#{')
q.format(variable)
q.text("}")
end
|