Module: Rubocop::Cop::Util

Defined in:
lib/rubocop/cop/util.rb

Overview

This module contains a collection of useful utility methods.

Class Method Summary collapse

Class Method Details

.block_length(block_node) ⇒ Object



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

def block_length(block_node)
  block_node.loc.end.line - block_node.loc.begin.line
end

.strip_quotes(str) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubocop/cop/util.rb', line 9

def strip_quotes(str)
  if str[0] == '"' || str[0] == "'"
    str[0] = ''
    str[-1] = ''
  else
    # we're dealing with %q or %Q
    str[0, 3] = ''
    str[-1] = ''
  end

  str
end

.symbolize_keys(hash) ⇒ Object



26
27
28
# File 'lib/rubocop/cop/util.rb', line 26

def symbolize_keys(hash)
  Hash[hash.map { |(k, v)| [k.to_sym, v] }] if hash
end