Skip to content

Instantly share code, notes, and snippets.

@pragdave
Created September 20, 2010 22:54
Show Gist options
  • Save pragdave/588809 to your computer and use it in GitHub Desktop.
Save pragdave/588809 to your computer and use it in GitHub Desktop.
require 'coverage'
Coverage.start
STDOUT.reopen("/dev/null")
require_relative 'fizzbuzz.rb'
Coverage.result.each do |file_name, counts|
File.readlines(file_name).each_with_index do |code_line, line_number|
count = counts[line_number] || "--"
STDERR.printf "%3s: %s", count, code_line
end
end
__END__
produces
1: 1.upto(100).with_object('') do |i, x|
100: if i % 3 == 0
33: x += 'Fizz'
--: end
100: if i % 5 == 0
20: x += 'Buzz'
--: end
100: if x.empty?
53: puts i
--: else
47: puts x
--: end
--: end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment