Skip to content

Instantly share code, notes, and snippets.

View jmhakvoort's full-sized avatar
🏗️
If you build it, they will come.

Jacques Hakvoort jmhakvoort

🏗️
If you build it, they will come.
  • Nedap Retail
  • Netherlands
  • 05:29 (UTC +01:00)
View GitHub Profile
@jmhakvoort
jmhakvoort / each_with_progress.rb
Last active February 9, 2026 13:54
Cool Enumerable#each_with_progress I once wrote so I can see how long iterating will take. I have waited too long on empty processes already. Most of the code is a blatant copy of existing code I found on the interwebs, but unfortunately I don't remember where. My contributions are mostly with the RAILS_ENV guard and the output.
module Enumerable
def each_with_progress(&block)
if ENV['RAILS_ENV'] == 'test'
each do |element|
block.call element
end
else
out = $stderr
time = Time.current
total = count