Class: RuboCop::Cop::RequireLibraryCorrector

Inherits:
Object
  • Object
show all
Extended by:
RangeHelp
Defined in:
lib/rubocop/cop/correctors/require_library_corrector.rb

Overview

This class ensures a require statement is present for a standard library determined by the variable library_name

Class Method Summary collapse

Class Method Details

.correct(corrector, node, library_name) ⇒ Object



11
12
13
14
15
# File 'lib/rubocop/cop/correctors/require_library_corrector.rb', line 11

def correct(corrector, node, library_name)
  node = node.parent while node.parent?
  node = node.children.first if node.begin_type?
  corrector.insert_before(node, require_statement(library_name))
end

.require_statement(library_name) ⇒ Object



17
18
19
# File 'lib/rubocop/cop/correctors/require_library_corrector.rb', line 17

def require_statement(library_name)
  "require '#{library_name}'\n"
end