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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:) ⇒ Const
constructor
A new instance of Const.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ Const
Returns a new instance of Const.
3803 3804 3805 3806 3807 |
# File 'lib/syntax_tree/node.rb', line 3803 def initialize(value:, location:) @value = value @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3801 3802 3803 |
# File 'lib/syntax_tree/node.rb', line 3801 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the name of the constant
3798 3799 3800 |
# File 'lib/syntax_tree/node.rb', line 3798 def value @value end |
Instance Method Details
#===(other) ⇒ Object
3838 3839 3840 |
# File 'lib/syntax_tree/node.rb', line 3838 def ===(other) other.is_a?(Const) && value === other.value end |
#accept(visitor) ⇒ Object
3809 3810 3811 |
# File 'lib/syntax_tree/node.rb', line 3809 def accept(visitor) visitor.visit_const(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3813 3814 3815 |
# File 'lib/syntax_tree/node.rb', line 3813 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 |
# File 'lib/syntax_tree/node.rb', line 3817 def copy(value: nil, location: nil) node = Const.new( value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
3830 3831 3832 |
# File 'lib/syntax_tree/node.rb', line 3830 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
3834 3835 3836 |
# File 'lib/syntax_tree/node.rb', line 3834 def format(q) q.text(value) end |