Try to fix RDoc markup for Enumerator

This commit is contained in:
Benoit Daloze 2022-12-26 15:28:37 +01:00
parent c182d46d24
commit d93d786338

View File

@ -73,7 +73,7 @@
* puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" } * puts %w[foo bar baz].map.with_index { |w, i| "#{i}:#{w}" }
* # => ["0:foo", "1:bar", "2:baz"] * # => ["0:foo", "1:bar", "2:baz"]
* *
* == External Iteration * == External Iteration
* *
* An Enumerator can also be used as an external iterator. * An Enumerator can also be used as an external iterator.
* For example, Enumerator#next returns the next value of the iterator * For example, Enumerator#next returns the next value of the iterator
@ -93,18 +93,19 @@
* *
* External iteration differs *significantly* from internal iteration * External iteration differs *significantly* from internal iteration
* due to using a Fiber: * due to using a Fiber:
* - The Fiber adds some overhead compared to internal enumeration. * - The Fiber adds some overhead compared to internal enumeration.
* - The stacktrace will only include the stack from the Enumerator, not above. * - The stacktrace will only include the stack from the Enumerator, not above.
* - Fiber-local variables are *not* inherited inside the Enumerator Fiber, * - Fiber-local variables are *not* inherited inside the Enumerator Fiber,
* which instead starts with no Fiber-local variables. * which instead starts with no Fiber-local variables.
* - Fiber storage variables *are* inherited and are designed * - Fiber storage variables *are* inherited and are designed
* to handle Enumerator Fibers. Assigning to a Fiber storage variable * to handle Enumerator Fibers. Assigning to a Fiber storage variable
* only affects the current Fiber, so if you want to change state * only affects the current Fiber, so if you want to change state
* in the caller Fiber of the Enumerator Fiber, you need to use an * in the caller Fiber of the Enumerator Fiber, you need to use an
* extra indirection (e.g., use some object in the Fiber storage * extra indirection (e.g., use some object in the Fiber storage
* variable and mutate some ivar of it). * variable and mutate some ivar of it).
* *
* Concretely: * Concretely:
*
* Thread.current[:fiber_local] = 1 * Thread.current[:fiber_local] = 1
* Fiber[:storage_var] = 1 * Fiber[:storage_var] = 1
* e = Enumerator.new do |y| * e = Enumerator.new do |y|
@ -120,7 +121,7 @@
* e.each { p _1 } * e.each { p _1 }
* p Fiber[:storage_var] # => 2 (it ran in the same Fiber/"stack" as the current Fiber) * p Fiber[:storage_var] # => 2 (it ran in the same Fiber/"stack" as the current Fiber)
* *
* == Convert External Iteration to Internal Iteration * == Convert External Iteration to Internal Iteration
* *
* You can use an external iterator to implement an internal iterator as follows: * You can use an external iterator to implement an internal iterator as follows:
* *