Module: RuboCop::Cop::Parentheses

Included in:
Style::ParenthesesAroundCondition, Style::RedundantParentheses
Defined in:
lib/rubocop/cop/mixin/parentheses.rb

Overview

Common functionality for handling parentheses.

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



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

def autocorrect(node)
  lambda do |corrector|
    corrector.remove(node.loc.begin)
    corrector.remove(node.loc.end)
  end
end

#parens_required?(node) ⇒ Boolean

Returns:

  • (Boolean)


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

def parens_required?(node)
  range  = node.source_range
  source = range.source_buffer.source
  source[range.begin_pos - 1] =~ /[a-z]/ ||
    source[range.end_pos] =~ /[a-z]/
end