In python I can get an iterator from any iterable with iter()
; and then I can call next(my_iter)
to get the next element.
Is there any equivalent in ruby/rails?
.to_enum
will yield the enumerator. For an example a.to_enum
will yield the enumerator and you can iterate it from there like a.to_enum.each{|x| p x}.
Or without loop, you can take the element like
p a.to_enum.next