skip to content

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 pageshow

explore

questions

page 2 of 2

In 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 s

Enumerator.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.

open as a page

showing 31–31 of 31