Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRubyEnumerable and custom eachSingle-choice MCQ

A custom `each` returns an Enumerator when called without a block via `enum_for`. Why is that pattern recommended, and what does `Words.new("a b c").each.next` return?

class Words include Enumerable def initialize(s) = @s = s def each return enum_for(:each) unless block_given? @s.split.each { |w| yield w } end end Words.new("a b c").each.next