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, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ Const
3738 3739 3740 3741 3742 |
# File 'lib/syntax_tree/node.rb', line 3738 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
3736 3737 3738 |
# File 'lib/syntax_tree/node.rb', line 3736 def comments @comments end |
#value ⇒ Object (readonly)
- String
-
the name of the constant
3733 3734 3735 |
# File 'lib/syntax_tree/node.rb', line 3733 def value @value end |
Instance Method Details
#===(other) ⇒ Object
3773 3774 3775 |
# File 'lib/syntax_tree/node.rb', line 3773 def ===(other) other.is_a?(Const) && value === other.value end |
#accept(visitor) ⇒ Object
3744 3745 3746 |
# File 'lib/syntax_tree/node.rb', line 3744 def accept(visitor) visitor.visit_const(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3748 3749 3750 |
# File 'lib/syntax_tree/node.rb', line 3748 def child_nodes [] end |
#copy(value: nil, location: nil) ⇒ Object
3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 |
# File 'lib/syntax_tree/node.rb', line 3752 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
3765 3766 3767 |
# File 'lib/syntax_tree/node.rb', line 3765 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
3769 3770 3771 |
# File 'lib/syntax_tree/node.rb', line 3769 def format(q) q.text(value) end |