Class: SyntaxTree::DynaSymbol
Overview
DynaSymbol represents a symbol literal that uses quotes to dynamically define its value.
:"#{variable}"
They can also be used as a special kind of dynamic hash key, as in:
{ "#{key}": value }
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#parts ⇒ Object
readonly
- Array[ StringDVar | StringEmbExpr | TStringContent ]
-
the parts of the dynamic symbol.
-
#quote ⇒ Object
readonly
- String
-
the quote used to delimit the dynamic symbol.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parts:, quote:, location:, comments: []) ⇒ DynaSymbol
constructor
A new instance of DynaSymbol.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(parts:, quote:, location:, comments: []) ⇒ DynaSymbol
Returns a new instance of DynaSymbol.
3955 3956 3957 3958 3959 3960 |
# File 'lib/syntax_tree/node.rb', line 3955 def initialize(parts:, quote:, location:, comments: []) @parts = parts @quote = quote @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3953 3954 3955 |
# File 'lib/syntax_tree/node.rb', line 3953 def comments @comments end |
#parts ⇒ Object (readonly)
- Array[ StringDVar | StringEmbExpr | TStringContent ]
-
the parts of the
dynamic symbol
3947 3948 3949 |
# File 'lib/syntax_tree/node.rb', line 3947 def parts @parts end |
#quote ⇒ Object (readonly)
- String
-
the quote used to delimit the dynamic symbol
3950 3951 3952 |
# File 'lib/syntax_tree/node.rb', line 3950 def quote @quote end |
Instance Method Details
#accept(visitor) ⇒ Object
3962 3963 3964 |
# File 'lib/syntax_tree/node.rb', line 3962 def accept(visitor) visitor.visit_dyna_symbol(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3966 3967 3968 |
# File 'lib/syntax_tree/node.rb', line 3966 def child_nodes parts end |
#deconstruct_keys(_keys) ⇒ Object
3972 3973 3974 |
# File 'lib/syntax_tree/node.rb', line 3972 def deconstruct_keys(_keys) { parts: parts, quote: quote, location: location, comments: comments } end |
#format(q) ⇒ Object
3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 |
# File 'lib/syntax_tree/node.rb', line 3976 def format(q) opening_quote, closing_quote = quotes(q) q.group(0, opening_quote, closing_quote) do parts.each do |part| if part.is_a?(TStringContent) value = Quotes.normalize(part.value, closing_quote) separator = -> { q.breakable(force: true, indent: false) } q.seplist(value.split(/\r?\n/, -1), separator) do |text| q.text(text) end else q.format(part) end end end end |