How to iterate an array in ruby

array = [1, 2, 3, 4, 5, 6]
array.each { |x| puts x }

Do we have any other way to iterate?

Why are you asking this?

The enumerator module is very useful, but also see loops in documentation:

for x in array
  puts x
end
2 Likes

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs