I am trying to grok the difference between a regular use of yield
in a function and the yielder
one uses with an Enumerable.
By a regular use of yield
I mean:
def fun
yield
end
fun do
puts "hello"
end
And by the Enumerator's yielder I mean:
def fun2
Enumerator.new do |yielder|
(0..2).each { |x| yielder << x }
end
end
fun2.each do |x|
puts x
end
How can I succinctly understand the difference between yield
and yielder
in terms of control flow and other relevant differences? Are they even comparable? Or is the yielder not really related to yield
despite the naming?