Project

General

Profile

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

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

View differences:

object.c
570 570
 *     "my string".yield_self {|s| s.upcase }   #=> "MY STRING"
571 571
 *     3.next.yield_self {|x| x**x }.to_s       #=> "256"
572 572
 *
573
 *  Good usage for +yield_self+ is values piping in long method
574
 *  chains:
575
 *
576
 *     require 'open-uri'
577
 *     require 'json'
578
 *
579
 *     construct_url(arguments).
580
 *       yield_self { |url| open(url).read }.
581
 *       yield_self { |response| JSON.parse(response) }
582
 *
583
 *  When called without block, the method returns +Enumerator+,
584
 *  which can be used, for example, for conditional
585
 *  circuit-breaking:
586
 *
587
 *     # meets condition, no-op
588
 *     1.yield_self.detect(&:odd?)            # => 1
589
 *     # does not meet condition, drop value
590
 *     2.yeild_self.detect(&:odd?)            # => nil
591
 *
573 592
 */
574 593

  
575 594
static VALUE