Class: SyntaxTree::Const
Overview
Const represents a literal value that looks like a constant. This could actually be a reference to a constant:
Constant
It could also be something that looks like a constant in another context, as in a method call to a capitalized method:
object.Constant
or a symbol that starts with a capital letter:
:Constant
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- String
-
the name of the constant.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Const
constructor
A new instance of Const.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Const
Returns a new instance of Const.
3161 3162 3163 3164 3165 |
# File 'lib/syntax_tree/node.rb', line 3161 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3159 3160 3161 |
# File 'lib/syntax_tree/node.rb', line 3159 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the name of the constant
3156 3157 3158 |
# File 'lib/syntax_tree/node.rb', line 3156 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
3167 3168 3169 |
# File 'lib/syntax_tree/node.rb', line 3167 def accept(visitor) visitor.visit_const(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3171 3172 3173 |
# File 'lib/syntax_tree/node.rb', line 3171 def child_nodes [] end |
#deconstruct_keys(_keys) ⇒ Object
3177 3178 3179 |
# File 'lib/syntax_tree/node.rb', line 3177 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
3181 3182 3183 |
# File 'lib/syntax_tree/node.rb', line 3181 def format(q) q.text(value) end |