Today marks the end of a 365 day journey of writing one Ruby programming tip everyday. It has been a long journey to consider new and interesting content in the realm of a Ruby and Rails programmer. I have learned so much and I am very happy to share this content with the world. For today’s final tip, in the 365 days of Ruby series, let’s look at how the each_slice() method does what it can to arrays. We can iterate over collections and grab the modulus of three and return a result when that happens. [1,2,3,4,5,6,7,8,9,10].each_with_index do |num, idx| puts "#{num}" if ((idx + 1) % 3 == 0) puts "end of line" end end   #=> 1 #=>[…]

This tip comes by way of: @starvo. By using a counter in your ruby console script you can gain insight into long running actions for your application. @photos = Photo.all count = @photos.count @photos.each_with_index do |photo, idx| # … do a bunch of processing puts "#{(100.0 * idx / count).round(2)}%" end   # When the script is run we will get a percentage complete counter like: #=> 0.1% #=> 0.2% #=> 0.3% #=> 0.4% #=> … :)