Module: RuboCop::Cop::IfNode

Overview

Common functionality for checking if nodes.

Instance Method Summary collapse

Instance Method Details

#elsif?(node) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/rubocop/cop/mixin/if_node.rb', line 17

def elsif?(node)
  node.loc.respond_to?(:keyword) && node.loc.keyword &&
    node.loc.keyword.is?('elsif')
end

#if_else?(node) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rubocop/cop/mixin/if_node.rb', line 22

def if_else?(node)
  node.loc.respond_to?(:else) && node.loc.else
end

#modifier_if?(node) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
# File 'lib/rubocop/cop/mixin/if_node.rb', line 7

def modifier_if?(node)
  node.loc.respond_to?(:keyword) &&
    %w(if unless).include?(node.loc.keyword.source) &&
    node.loc.respond_to?(:end) && node.loc.end.nil?
end

#ternary_op?(node) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rubocop/cop/mixin/if_node.rb', line 13

def ternary_op?(node)
  node.loc.respond_to?(:question)
end