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.
3772 3773 3774 3775 3776 |
# File 'lib/syntax_tree/node.rb', line 3772 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
3770 3771 3772 |
# File 'lib/syntax_tree/node.rb', line 3770 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the name of the constant
3767 3768 3769 |
# File 'lib/syntax_tree/node.rb', line 3767 def value @value end |
Instance Method Details
#===(other) ⇒ Object
3807 3808 3809 |
# File 'lib/syntax_tree/node.rb', line 3807 def ===(other) other.is_a?(Const) && value === other.value end |
#accept(visitor) ⇒ Object
3778 3779 3780 |
# File 'lib/syntax_tree/node.rb', line 3778 def accept(visitor) visitor.visit_const(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3782 3783 3784 |
# File 'lib/syntax_tree/node.rb', line 3782 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 |
# File 'lib/syntax_tree/node.rb', line 3786 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
3799 3800 3801 |
# File 'lib/syntax_tree/node.rb', line 3799 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
3803 3804 3805 |
# File 'lib/syntax_tree/node.rb', line 3803 def format(q) q.text(value) end |