Enumerable Methods
Enumerable's iterators, predicates, map and reduce, sorting and Enumerators, plus making your own class enumerable. Idiomatic Ruby is a chain of these calls, so interviewers read yours closely.
on this pageshowhide
explore
- Each-Style Iterators5 questions
- Predicates & Selection5 questions
- Mapping & Reducing6 questions
- Sorting & Ordering5 questions
- Enumerators & Laziness5 questions
- Custom Collection Classes5 questions
questions
page 2 of 2In Ruby 4.0, how would you wrap an endless, paginated stock-tick API as an Enumerator using Enumerator.new or Enumerator.produce?
level: seniorimportance: nice to knowfreq 22%
basics
~20 sEnumerator.new { |y| ... } runs its block only when iterated, pushing each tick with y << tick as it fetches pages. Enumerator.produce(first) { |prev| ... } derives each value from the last and stops on StopIteration; Ruby 4.0 added its size: keyword.
showing 31–31 of 31