Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4631

"for" vs "each" in Ruby

$
0
0

I just had a quick question regarding loops in Ruby. Is there a difference between these two ways of iterating through a collection?

# way 1@collection.each do |item|  # do whateverend# way 2for item in @collection  # do whateverend

Just wondering if these are exactly the same or if maybe there's a subtle difference (possibly when @collection is nil).


Viewing all articles
Browse latest Browse all 4631

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>