Class: RuboCop::AST::NodePattern::Node
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Classes:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::RuboCop::SimpleForwardable ,
Parser::AST::Node
|
|
Instance Chain:
self,
::RuboCop::AST::Descendence ,
Parser::AST::Node
|
|
Inherits: |
Parser::AST::Node
|
Defined in: | lib/rubocop/ast/node_pattern/node.rb |
Overview
Base class for AST Nodes of a NodePattern
Constant Summary
-
FunctionCall =
# File 'lib/rubocop/ast/node_pattern/node.rb', line 139Predicate
-
INT_TO_RANGE =
private
# File 'lib/rubocop/ast/node_pattern/node.rb', line 81Hash.new { |h, k| h[k] = k..k }
-
MAP =
Registry
Hash.new(Node).merge!( sequence: Sequence, repetition: Repetition, rest: Rest, capture: Capture, predicate: Predicate, any_order: AnyOrder, function_call: FunctionCall, subsequence: Subsequence, union: Union ).freeze
-
MATCHES_WITHIN_SET =
private
# File 'lib/rubocop/ast/node_pattern/node.rb', line 11%i[symbol number string].to_set.freeze
Class Method Summary
::RuboCop::SimpleForwardable
- Extended
Instance Attribute Summary
- #capture? ⇒ Boolean readonly
-
#matches_within_set? ⇒ Boolean
readonly
that matches within a Set (e.g.
-
#rest? ⇒ Boolean
readonly
To be overridden by subclasses.
- #variadic? ⇒ Boolean readonly
Instance Method Summary
-
#arity ⇒ Integer, Range
Note:
arity.end
may beFloat::INFINITY
. - #arity_range ⇒ Range
- #child ⇒ Node
- #children_nodes ⇒ Array<Node>
- #in_sequence_head ⇒ Array<Node>?
- #nb_captures ⇒ Integer
- #source_range
- #with(type: @type, children: @children, location: @location)
::RuboCop::AST::Descendence
- Included
#child_nodes | Returns an array of child nodes. |
#descendants | Returns an array of descendant nodes. |
#each_child_node | Calls the given block for each child node. |
#each_descendant | Calls the given block for each descendant node with depth first order. |
#each_node | Calls the given block for the receiver and each descendant node in depth-first order. |
Instance Attribute Details
#capture? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/rubocop/ast/node_pattern/node.rb', line 22
def capture? false end
#matches_within_set? ⇒ Boolean
(readonly)
that matches within a Set (e.g. 42
, :sym
but not /regexp/
)
# File 'lib/rubocop/ast/node_pattern/node.rb', line 63
def matches_within_set? MATCHES_WITHIN_SET.include?(type) end
#rest? ⇒ Boolean
(readonly)
To be overridden by subclasses
# File 'lib/rubocop/ast/node_pattern/node.rb', line 18
def rest? false end
#variadic? ⇒ Boolean
(readonly)
# File 'lib/rubocop/ast/node_pattern/node.rb', line 57
def variadic? arity.is_a?(Range) end
Instance Method Details
#arity ⇒ Integer
, Range
Note: arity.end
may be Float::INFINITY
# File 'lib/rubocop/ast/node_pattern/node.rb', line 28
def arity 1 end
#arity_range ⇒ Range
# File 'lib/rubocop/ast/node_pattern/node.rb', line 68
def arity_range a = arity a.is_a?(Range) ? a : INT_TO_RANGE[a] end
#child ⇒ Node
# File 'lib/rubocop/ast/node_pattern/node.rb', line 47
def child children[0] end
#children_nodes ⇒ Array
<Node
>
# File 'lib/rubocop/ast/node_pattern/node.rb', line 42
def children_nodes children.grep(Node) end
#in_sequence_head ⇒ Array
<Node
>?
# File 'lib/rubocop/ast/node_pattern/node.rb', line 33
def in_sequence_head nil end
#nb_captures ⇒ Integer
# File 'lib/rubocop/ast/node_pattern/node.rb', line 52
def nb_captures children_nodes.sum(&:nb_captures) end
#source_range
[ GitHub ]# File 'lib/rubocop/ast/node_pattern/node.rb', line 77
def source_range loc.expression end
#with(type: @type, children: @children, location: @location)
[ GitHub ]# File 'lib/rubocop/ast/node_pattern/node.rb', line 73
def with(type: @type, children: @children, location: @location) self.class.new(type, children, { location: location }) end