Module: RuboCop::Cop::Parentheses

Included in:
RuboCop::Cop::Performance::PushSplat, 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



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

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

#parens_required?(node) ⇒ Boolean

Returns:

  • (Boolean)


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

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