Enumerators And Iterators In Ruby - Study Mode

[#1] How do you create a custom enumerator in Ruby?
Correct Answer

(C) By extending the Enumerator class

[#2] What is the purpose of the each_with_index method in Ruby enumerators?
Correct Answer

(B) To iterate over each element in a collection along with its index

[#3] What does the cycle method do in Ruby enumerators?
Correct Answer

(C) Iterates over each element in a collection indefinitely

[#4] What does the find method do in Ruby enumerators?
Correct Answer

(D) Returns the first element that satisfies a given condition

[#5] What is the purpose of the times method in Ruby enumerators?
Correct Answer

(A) Executes a block of code a specified number of times