class IRB::SourceFinder::Source

Attributes

file [R]
line [R]

Public Class Methods

new (file, line, ast_source = nil)
# File lib/irb/source_finder.rb, line 11
def initialize(file, line, ast_source = nil)
  @file = file
  @line = line
  @ast_source = ast_source
end

Public Instance Methods

binary_file? ()
# File lib/irb/source_finder.rb, line 21
def binary_file?
  # If the line is zero, it means that the target's source is probably in a binary file.
  @line.zero?
end
colorized_content ()
# File lib/irb/source_finder.rb, line 30
def colorized_content
  if !binary_file? && file_exist?
    end_line = find_end
    # To correctly colorize, we need to colorize full content and extract the relevant lines.
    colored = IRB::Color.colorize_code(file_content)
    colored.lines[@line - 1...end_line].join
  elsif @ast_source
    IRB::Color.colorize_code(@ast_source)
  end
end
file_content ()
# File lib/irb/source_finder.rb, line 26
def file_content
  @file_content ||= File.read(@file)
end
file_exist? ()
# File lib/irb/source_finder.rb, line 17
def file_exist?
  File.exist?(@file)
end