Project

General

Profile

Bug #14436 ยป yield-self-docs.patch

zverok (Victor Shepelev), 02/02/2018 05:29 PM

View differences:

object.c
* "my string".yield_self {|s| s.upcase } #=> "MY STRING"
* 3.next.yield_self {|x| x**x }.to_s #=> "256"
*
* Good usage for +yield_self+ is values piping in long method
* chains:
*
* require 'open-uri'
* require 'json'
*
* construct_url(arguments).
* yield_self { |url| open(url).read }.
* yield_self { |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
* # does not meet condition, drop value
* 2.yeild_self.detect(&:odd?) # => nil
*
*/
static VALUE
    (1-1/1)