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.
3819 3820 3821 3822 3823 |
# File 'lib/syntax_tree/node.rb', line 3819 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
3817 3818 3819 |
# File 'lib/syntax_tree/node.rb', line 3817 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the name of the constant
3814 3815 3816 |
# File 'lib/syntax_tree/node.rb', line 3814 def value @value end |
Instance Method Details
#===(other) ⇒ Object
3854 3855 3856 |
# File 'lib/syntax_tree/node.rb', line 3854 def ===(other) other.is_a?(Const) && value === other.value end |
#accept(visitor) ⇒ Object
3825 3826 3827 |
# File 'lib/syntax_tree/node.rb', line 3825 def accept(visitor) visitor.visit_const(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3829 3830 3831 |
# File 'lib/syntax_tree/node.rb', line 3829 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 |
# File 'lib/syntax_tree/node.rb', line 3833 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
3846 3847 3848 |
# File 'lib/syntax_tree/node.rb', line 3846 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
3850 3851 3852 |
# File 'lib/syntax_tree/node.rb', line 3850 def format(q) q.text(value) end |