How to iterate over all but first element of an enumerable
How about this?
[1,2,3].drop(1).each {|x| puts x }
# >> 2
# >> 3
Here's how you can continue walking the iterator
a = [1,2,3]
b = a.each # => #<Enumerator: [1, 2, 3]:each>
b.next # skip first one
loop do
c = b.next
puts c
end
# >> 2
# >> 3
You could do
a.drop(1).each do |x| puts x end
EDIT:
Use the map
method
b = [1,2,3].drop(1).map{|x| x}
=> b will be [2, 3]