Iterators in Ruby — Think Less Looping, More Logic

Ruby Iterators — When Loops Just Aren’t Elegant Enough Ruby Iterators — When Loops Just Aren’t Elegant Enough Published: June 24, 2025 • CodeCraft Diaries #7 "If you've been writing `for` loops in Ruby like it's 1999, this one's for you." Let’s be real: loops are the bread and butter of programming. But in Ruby? You don’t just butter the bread — you toast it, drizzle it with honey, and serve it like a gourmet dev snack. Welcome to the elegant world of Ruby iterators — where looping is expressive, concise, and kinda beautiful. 🚶 Why Not Just Use a Loop? You can, of course: for i in 1..3 puts i end But Ruby gives us cooler tools. Imagine replacing that clunky loop with something like: (1..3).each { |i| puts i } Cleaner. Readable. Ruby-esque. 🔄 Meet Your Iterator Friends 1. each — The Friendly Tour Guide ["coffee", "code", "chai"].each do |item| puts ...