Class: RubbyCop::AST::SendNode
- Defined in:
- lib/rubbycop/ast/node/send_node.rb
Overview
A node extension for ‘send` nodes. This will be used in place of a plain node when the builder constructs the AST, making its methods available to all `send` nodes within RubbyCop.
Constant Summary
Constants inherited from Node
Node::BASIC_LITERALS, Node::COMPARISON_OPERATORS, Node::COMPOSITE_LITERALS, Node::FALSEY_LITERALS, Node::IMMUTABLE_LITERALS, Node::KEYWORDS, Node::LITERALS, Node::MUTABLE_LITERALS, Node::OPERATOR_KEYWORDS, Node::REFERENCES, Node::SPECIAL_KEYWORDS, Node::TRUTHY_LITERALS, Node::VARIABLES
Instance Method Summary collapse
-
#arguments ⇒ Array<Node>
An array containing the arguments of the method invocation.
-
#arguments? ⇒ Boolean
Checks whether this method was invoked with arguments.
-
#assignment_method? ⇒ Boolean
Checks whether the invoked method is an assignment method.
-
#bang_method? ⇒ Boolean
Checks whether the invoked method is a bang method.
-
#block_argument? ⇒ Boolean
Whether the last argument of the method invocation is a block pass, i.e.
-
#camel_case_method? ⇒ Boolean
Checks whether the invoked method is a camel case method, e.g.
-
#command?(name) ⇒ Boolean
Checks whether the method name matches the argument and has an implicit receiver.
-
#comparison_method? ⇒ Boolean
Checks whether the invoked method is a comparison method.
-
#dot? ⇒ Boolean
Checks whether the method call uses a dot to connect the receiver and the method name.
-
#double_colon? ⇒ Boolean
Checks whether the method call uses a double colon to connect the receiver and the method name.
-
#first_argument ⇒ Node?
A shorthand for getting the first argument of the method invocation.
-
#implicit_call? ⇒ Boolean
Checks whether the method call is of the implicit form of ‘#call`, e.g.
-
#last_argument ⇒ Node?
A shorthand for getting the last argument of the method invocation.
-
#macro? ⇒ Boolean
Checks whether the method is a macro method.
-
#method?(name) ⇒ Boolean
Checks whether the method name matches the argument.
-
#method_name ⇒ Symbol
The name of the invoked method called as a string.
-
#node_parts ⇒ Array
Custom destructuring method.
-
#operator_method? ⇒ Boolean
Checks whether the invoked method is an operator method.
-
#parenthesized? ⇒ Boolean
Checks whether this method invocation’s arguments are wrapped in parentheses.
-
#predicate_method? ⇒ Boolean
Checks whether the invoked method is a predicate method.
-
#receiver ⇒ Node?
The receiving node of the method invocation.
-
#self_receiver? ⇒ Boolean
Checks whether the receiver of this method invocation is ‘self`.
-
#setter_method? ⇒ Boolean
Checks whether the invoked method is a setter method.
-
#splat_argument? ⇒ Boolean
Checks whether any argument of the method invocation is a splat argument, i.e.
Methods inherited from Node
#ancestors, #argument?, #asgn_method_call?, #basic_literal?, #binary_operation?, #chained?, #child_nodes, #complete!, #complete?, #const_name, def_matcher, #defined_module, #defined_module_name, #descendants, #each_ancestor, #each_child_node, #each_descendant, #each_node, #falsey_literal?, #immutable_literal?, #initialize, #keyword?, #keyword_bang?, #keyword_not?, #literal?, #multiline?, #mutable_literal?, #numeric_type?, #operator_keyword?, #parent, #parent_module_name, #pure?, #reference?, #sibling_index, #single_line?, #source, #source_range, #special_keyword?, #truthy_literal?, #unary_operation?, #updated, #value_used?, #variable?
Methods included from Sexp
Constructor Details
This class inherits a constructor from RubbyCop::AST::Node
Instance Method Details
#arguments ⇒ Array<Node>
An array containing the arguments of the method invocation.
54 55 56 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 54 def arguments node_parts[2..-1] end |
#arguments? ⇒ Boolean
Checks whether this method was invoked with arguments.
79 80 81 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 79 def arguments? !arguments.empty? end |
#assignment_method? ⇒ Boolean
Checks whether the invoked method is an assignment method.
116 117 118 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 116 def assignment_method? !comparison_method? && method_name.to_s.end_with?('=') end |
#bang_method? ⇒ Boolean
Checks whether the invoked method is a bang method.
165 166 167 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 165 def bang_method? method_name.to_s.end_with?('!') end |
#block_argument? ⇒ Boolean
Whether the last argument of the method invocation is a block pass, i.e. ‘&block`.
181 182 183 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 181 def block_argument? arguments? && last_argument.block_pass_type? end |
#camel_case_method? ⇒ Boolean
Checks whether the invoked method is a camel case method, e.g. ‘Integer()`.
173 174 175 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 173 def camel_case_method? method_name.to_s =~ /\A[A-Z]/ end |
#command?(name) ⇒ Boolean
Checks whether the method name matches the argument and has an implicit receiver.
47 48 49 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 47 def command?(name) !receiver && method?(name) end |
#comparison_method? ⇒ Boolean
Checks whether the invoked method is a comparison method.
109 110 111 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 109 def comparison_method? COMPARISON_OPERATORS.include?(method_name) end |
#dot? ⇒ Boolean
Checks whether the method call uses a dot to connect the receiver and the method name.
This is useful for comparison operators, which can be called either with or without a dot, i.e. ‘foo == bar` or `foo.== bar`.
127 128 129 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 127 def dot? loc.dot && loc.dot.is?('.') end |
#double_colon? ⇒ Boolean
Checks whether the method call uses a double colon to connect the receiver and the method name.
135 136 137 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 135 def double_colon? loc.dot && loc.dot.is?('::') end |
#first_argument ⇒ Node?
A shorthand for getting the first argument of the method invocation. Equivalent to ‘arguments.first`.
63 64 65 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 63 def first_argument arguments[0] end |
#implicit_call? ⇒ Boolean
Checks whether the method call is of the implicit form of ‘#call`, e.g. `foo.(bar)`.
151 152 153 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 151 def implicit_call? method_name == :call && !loc.selector end |
#last_argument ⇒ Node?
A shorthand for getting the last argument of the method invocation. Equivalent to ‘arguments.last`.
72 73 74 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 72 def last_argument arguments[-1] end |
#macro? ⇒ Boolean
This does not include DSLs that use nested blocks, like RSpec
Checks whether the method is a macro method. A macro method is defined as a method that sits in a class- or module body and has an implicit receiver.
38 39 40 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 38 def macro? !receiver && macro_scope? end |
#method?(name) ⇒ Boolean
Checks whether the method name matches the argument.
27 28 29 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 27 def method?(name) method_name == name.to_sym end |
#method_name ⇒ Symbol
The name of the invoked method called as a string.
19 20 21 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 19 def method_name node_parts[1] end |
#node_parts ⇒ Array
Custom destructuring method. This can be used to normalize destructuring for different variations of the node.
197 198 199 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 197 def node_parts to_a end |
#operator_method? ⇒ Boolean
Checks whether the invoked method is an operator method.
102 103 104 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 102 def operator_method? RubbyCop::Cop::Util::OPERATOR_METHODS.include?(method_name) end |
#parenthesized? ⇒ Boolean
Checks whether this method invocation’s arguments are wrapped in parentheses.
88 89 90 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 88 def parenthesized? loc.end && loc.end.is?(')') end |
#predicate_method? ⇒ Boolean
Checks whether the invoked method is a predicate method.
158 159 160 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 158 def predicate_method? method_name.to_s.end_with?('?') end |
#receiver ⇒ Node?
The receiving node of the method invocation.
12 13 14 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 12 def receiver node_parts[0] end |
#self_receiver? ⇒ Boolean
Checks whether the receiver of this method invocation is ‘self`.
143 144 145 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 143 def self_receiver? receiver && receiver.self_type? end |
#setter_method? ⇒ Boolean
Checks whether the invoked method is a setter method.
95 96 97 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 95 def setter_method? loc.operator end |
#splat_argument? ⇒ Boolean
Checks whether any argument of the method invocation is a splat argument, i.e. ‘*splat`.
189 190 191 |
# File 'lib/rubbycop/ast/node/send_node.rb', line 189 def splat_argument? arguments? && arguments.any?(&:splat_type?) end |