Skip to Content Skip to Search

Wraps a regular expression that will iterate through a file’s lines and test each one for the given pattern.

Methods
A

Instance Public methods

annotations(file)

# File railties/lib/rails/source_annotation_extractor.rb, line 32
def annotations(file)
  lineno = 0

  # Read as binary to bypass Encoding.default_internal transcoding, which
  # raises on invalid bytes, then treat the source as UTF-8 like Prism does.
  File.readlines(file, encoding: Encoding::BINARY).inject([]) do |list, line|
    lineno += 1
    line.force_encoding(Encoding::UTF_8).scrub!
    next list unless line =~ pattern
    list << Annotation.new(lineno, $1, $2)
  end
end