module RuboCop::Cop::IfNode
Common functionality for checking if nodes.
Public Instance Methods
elsif?(node)
click to toggle source
# 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)
click to toggle source
# File lib/rubocop/cop/mixin/if_node.rb, line 22 def if_else?(node) node.loc.respond_to?(:else) && node.loc.else end
if_node_parts(node)
click to toggle source
# File lib/rubocop/cop/mixin/if_node.rb, line 26 def if_node_parts(node) case node.loc.keyword.source when 'if', 'elsif' then condition, body, else_clause = *node when 'unless' then condition, else_clause, body = *node else condition, body = *node end [condition, body, else_clause] end
modifier_if?(node)
click to toggle source
# File lib/rubocop/cop/mixin/if_node.rb, line 11 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?(node)
click to toggle source
# File lib/rubocop/cop/mixin/if_node.rb, line 7 def ternary?(node) node.loc.respond_to?(:question) end