Yes, it's guaranteed; #to_a
effectively just collects the results of #each
and returns them in a new array.
enum_to_a creates a new array, then calls collect_all
as a block parameter to its own each
. collect_all
simply performs rb_ary_push(ary, i);
, which pushes the given value onto the created array. In Ruby, this would be:
array = []
enum.each {|v| array.push v }
Hope that helps!