How to create a terminal progress indicators in Ruby

Posted . Visible to the public.

For long running scripts it is useful to show a indicator for the progress in the terminal. Alternatively you can use a gem like paul/progress_bar.

count = User.count
index = 0

User.find_each do |user|
  printf("Progress: %.2f%%\r", index.to_f / count * 100)
  user.update!(role: 'member')
  index += 1
end

Preview video

Image

Last edit
Emanuel
Attachments
License
Source code in this card is licensed under the MIT License.
Posted by Emanuel to makandra dev (2025-03-24 07:10)