Stream file lines with File.each_line

Crystal
require "file"

def each_record_line(path : String, &block : String ->)
  File.each_line(path, chomp: true) do |line|
    text = line.strip
    next if text.empty? || text.starts_with?('#')
    block.call(text)
  end
rescue ex : File::NotFoundError
  raise ArgumentError.new("missing file: #{path} (#{ex.message})")
end

each_record_line("config.txt") { |line| puts line }