Misc #16126 ยป docs-bugs.patch
| enumerator.c | ||
|---|---|---|
|
* A class which allows both internal and external iteration.
|
||
|
*
|
||
|
* An Enumerator can be created by the following methods.
|
||
|
* - Kernel#to_enum
|
||
|
* - Kernel#enum_for
|
||
|
* - Object#to_enum
|
||
|
* - Object#enum_for
|
||
|
* - Enumerator.new
|
||
|
*
|
||
|
* Most methods have two forms: a block form where the contents
|
||
| ... | ... | |
|
* In the second, deprecated, form, a generated Enumerator iterates over the
|
||
|
* given object using the given method with the given arguments passed.
|
||
|
*
|
||
|
* Use of this form is discouraged. Use Kernel#enum_for or Kernel#to_enum
|
||
|
* Use of this form is discouraged. Use Object#enum_for or Object#to_enum
|
||
|
* instead.
|
||
|
*
|
||
|
* e = Enumerator.new(ObjectSpace, :each_object)
|
||
| ... | ... | |
|
*
|
||
|
* For example, continuing from the example in Object#to_enum:
|
||
|
*
|
||
|
* # See Kernel#to_enum for the definition of repeat
|
||
|
* # See Object#to_enum for the definition of repeat
|
||
|
* r = 1..Float::INFINITY
|
||
|
* r.repeat(2).first(5) # => [1, 1, 2, 2, 3]
|
||
|
* r.repeat(2).class # => Enumerator
|
||
| error.c | ||
|---|---|---|
|
/*
|
||
|
* call-seq:
|
||
|
* warn(msg, ...) -> nil
|
||
|
* warn(*msgs, uplevel: nil) -> nil
|
||
|
*
|
||
|
* If warnings have been disabled (for example with the
|
||
|
* <code>-W0</code> flag), does nothing. Otherwise,
|
||
| ... | ... | |
|
* * IndexError
|
||
|
* * KeyError
|
||
|
* * StopIteration
|
||
|
* * ClosedQueueError
|
||
|
* * LocalJumpError
|
||
|
* * NameError
|
||
|
* * NoMethodError
|
||
| object.c | ||
|---|---|---|
|
* 3.next.then {|x| x**x }.to_s #=> "256"
|
||
|
* "my string".yield_self {|s| s.upcase } #=> "MY STRING"
|
||
|
*
|
||
|
* Good usage for +yield_self+ is value piping in method chains:
|
||
|
* Good usage for +then+ is value piping in method chains:
|
||
|
*
|
||
|
* require 'open-uri'
|
||
|
* require 'json'
|
||
|
*
|
||
|
* construct_url(arguments).
|
||
|
* yield_self {|url| open(url).read }.
|
||
|
* yield_self {|response| JSON.parse(response) }
|
||
|
* then {|url| open(url).read }.
|
||
|
* then {|response| JSON.parse(response) }
|
||
|
*
|
||
|
* When called without block, the method returns +Enumerator+,
|
||
|
* which can be used, for example, for conditional
|
||
|
* circuit-breaking:
|
||
|
*
|
||
|
* # meets condition, no-op
|
||
|
* 1.yield_self.detect(&:odd?) # => 1
|
||
|
* 1.then.detect(&:odd?) # => 1
|
||
|
* # does not meet condition, drop value
|
||
|
* 2.yield_self.detect(&:odd?) # => nil
|
||
|
* 2.then.detect(&:odd?) # => nil
|
||
|
*
|
||
|
*/
|
||