Module: Byebug::FileFunctions

Included in:
Command, CommandProcessor, InfoFunctions, Interface, RegularState
Defined in:
lib/byebug/helper.rb

Overview

Utilities for interaction with files

Instance Method Summary collapse

Instance Method Details

#get_line(filename, lineno) ⇒ Object

Reads line number lineno from file named filename


16
17
18
19
20
21
# File 'lib/byebug/helper.rb', line 16

def get_line(filename, lineno)
  File.open(filename) do |f|
    f.gets until f.lineno == lineno - 1
    f.gets
  end
end

#get_lines(filename) ⇒ Object

Reads lines of source file filename into an array


9
10
11
# File 'lib/byebug/helper.rb', line 9

def get_lines(filename)
  File.foreach(filename).reduce([]) { |a, e| a << e.chomp }
end

#n_lines(filename) ⇒ Object

Returns the number of lines in file filename in a portable, one-line-at-a-time way.


27
28
29
# File 'lib/byebug/helper.rb', line 27

def n_lines(filename)
  File.foreach(filename).reduce(0) { |a, _e| a + 1 }
end

#normalize(filename) ⇒ Object

Regularize file name.


34
35
36
37
38
39
40
41
42
# File 'lib/byebug/helper.rb', line 34

def normalize(filename)
  return filename if ['(irb)', '-e'].include?(filename)

  return File.basename(filename) if Setting[:basename]

  path = File.expand_path(filename)

  File.exist?(path) ? File.realpath(path) : filename
end