Class: SyntaxTree::ConstPathField
Overview
ConstPathField represents the child node of some kind of assignment. It represents when you’re assigning to a constant that is being referenced as a child of another variable.
object::Const = value
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#constant ⇒ Object
readonly
- Const
-
the constant itself.
-
#parent ⇒ Object
readonly
- Node
-
the source of the constant.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(parent: nil, constant: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(parent:, constant:, location:) ⇒ ConstPathField
constructor
A new instance of ConstPathField.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(parent:, constant:, location:) ⇒ ConstPathField
Returns a new instance of ConstPathField.
3859 3860 3861 3862 3863 3864 |
# File 'lib/syntax_tree/node.rb', line 3859 def initialize(parent:, constant:, location:) @parent = parent @constant = constant @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
3857 3858 3859 |
# File 'lib/syntax_tree/node.rb', line 3857 def comments @comments end |
#constant ⇒ Object (readonly)
- Const
-
the constant itself
3854 3855 3856 |
# File 'lib/syntax_tree/node.rb', line 3854 def constant @constant end |
#parent ⇒ Object (readonly)
- Node
-
the source of the constant
3851 3852 3853 |
# File 'lib/syntax_tree/node.rb', line 3851 def parent @parent end |
Instance Method Details
#===(other) ⇒ Object
3903 3904 3905 3906 |
# File 'lib/syntax_tree/node.rb', line 3903 def ===(other) other.is_a?(ConstPathField) && parent === other.parent && constant === other.constant end |
#accept(visitor) ⇒ Object
3866 3867 3868 |
# File 'lib/syntax_tree/node.rb', line 3866 def accept(visitor) visitor.visit_const_path_field(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
3870 3871 3872 |
# File 'lib/syntax_tree/node.rb', line 3870 def child_nodes [parent, constant] end |
#copy(parent: nil, constant: nil, location: nil) ⇒ Object
3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 |
# File 'lib/syntax_tree/node.rb', line 3874 def copy(parent: nil, constant: nil, location: nil) node = ConstPathField.new( parent: parent || self.parent, constant: constant || self.constant, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
3888 3889 3890 3891 3892 3893 3894 3895 |
# File 'lib/syntax_tree/node.rb', line 3888 def deconstruct_keys(_keys) { parent: parent, constant: constant, location: location, comments: comments } end |
#format(q) ⇒ Object
3897 3898 3899 3900 3901 |
# File 'lib/syntax_tree/node.rb', line 3897 def format(q) q.format(parent) q.text("::") q.format(constant) end |