Module: RuboCop::Cop::IfNode

Overview

Common functionality for checking if nodes.

Instance Method Summary collapse

Instance Method Details

#elsif?(node) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/rubocop/cop/mixin/if_node.rb', line 15

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

#if_else?(node) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rubocop/cop/mixin/if_node.rb', line 20

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

#modifier_if?(node) ⇒ Boolean

Returns:

  • (Boolean)


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

def modifier_if?(node)
  node.loc.end.nil?
end

#ternary_op?(node) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/rubocop/cop/mixin/if_node.rb', line 11

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