Method: File.each_line

Defined in:
lib/ronin/extensions/file.rb

.each_line(path) {|line| ... } ⇒ Enumerator

Reads each line from the file.

Examples:

File.each_line('passwords.txt') do |line|
  # ...
end

Parameters:

  • path (String)

    The path of the file.

Yields:

  • (line)

    The given block will be passed each line.

Yield Parameters:

  • line (String)

    A line from the file, with the trailing newline characters removed.

Returns:

  • (Enumerator)

    If no block is given, an Enumerator will be returned.

Since:

  • 0.3.0


46
47
48
49
50
# File 'lib/ronin/extensions/file.rb', line 46

def File.each_line(path)
  return enum_for(__method__,path) unless block_given?

  File.foreach(path) { |line| yield line.chomp }
end