diff --git a/lib/rubocop/ast/node/if_node.rb b/lib/rubocop/ast/node/if_node.rb index 3bd4a1192..e7e6aca47 100644 --- a/lib/rubocop/ast/node/if_node.rb +++ b/lib/rubocop/ast/node/if_node.rb @@ -40,14 +40,14 @@ def elsif? # # @return [Boolean] whether the node has an `else` clause def else? - loc.respond_to?(:else) && loc.else + loc?(:else) end # Checks whether the `if` node is a ternary operator. # # @return [Boolean] whether the `if` node is a ternary operator def ternary? - loc.respond_to?(:question) + loc?(:question) end # Returns the keyword of the `if` statement as a string. Returns an empty diff --git a/lib/rubocop/ast/node/mixin/method_dispatch_node.rb b/lib/rubocop/ast/node/mixin/method_dispatch_node.rb index a1fb3716c..ad0e54beb 100644 --- a/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +++ b/lib/rubocop/ast/node/mixin/method_dispatch_node.rb @@ -32,7 +32,7 @@ def method_name # # @return [Parser::Source::Range] the source range for the method name or keyword def selector - if loc.respond_to? :keyword + if loc?(:keyword) loc.keyword else loc.selector @@ -105,7 +105,7 @@ def command?(name) # # @return [Boolean] whether the dispatched method is a setter def setter_method? - loc.respond_to?(:operator) && loc.operator + loc?(:operator) end alias assignment? setter_method?