[前][次][番号順一覧][スレッド一覧]

ruby-changes:46857

From: stomar <ko1@a...>
Date: Wed, 31 May 2017 03:17:59 +0900 (JST)
Subject: [ruby-changes:46857] stomar:r58972 (trunk): object.c: improve docs

stomar	2017-05-31 03:17:55 +0900 (Wed, 31 May 2017)

  New Revision: 58972

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58972

  Log:
    object.c: improve docs
    
    * object.c: [DOC] add an example for Object#yield_self that
      better illustrates its purpose; other small improvements.
      Reported by Vitaly Tatarintsev (ck3g).  Patch by Marcus Stollsteimer.
      [Fix GH-1637]
    
    * object.c: [DOC] improve docs for Object#{itself,tap}.

  Modified files:
    trunk/object.c
Index: object.c
===================================================================
--- object.c	(revision 58971)
+++ object.c	(revision 58972)
@@ -493,12 +493,12 @@ rb_obj_dup(VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L493
 
 /*
  *  call-seq:
- *     obj.itself -> an_object
+ *     obj.itself    -> obj
  *
- *  Returns <i>obj</i>.
+ *  Returns the receiver.
  *
- *	string = 'my string' #=> "my string"
- *	string.itself.object_id == string.object_id #=> true
+ *     string = "my string"
+ *     string.itself.object_id == string.object_id   #=> true
  *
  */
 
@@ -516,11 +516,12 @@ rb_obj_size(VALUE self, VALUE args, VALU https://github.com/ruby/ruby/blob/trunk/object.c#L516
 
 /*
  *  call-seq:
- *     obj.yield_self {|_obj|...} -> an_object
+ *     obj.yield_self {|x| block }    -> an_object
  *
- *  Yields <i>obj</i> and returns the result.
+ *  Yields self to the block and returns the result of the block.
  *
- *	'my string'.yield_self {|s|s.upcase} #=> "MY STRING"
+ *     "my string".yield_self {|s| s.upcase }   #=> "MY STRING"
+ *     3.next.yield_self {|x| x**x }.to_s       #=> "256"
  *
  */
 
@@ -782,16 +783,16 @@ rb_class_search_ancestor(VALUE cl, VALUE https://github.com/ruby/ruby/blob/trunk/object.c#L783
 
 /*
  *  call-seq:
- *     obj.tap{|x| block }    -> obj
+ *     obj.tap {|x| block }    -> obj
  *
  *  Yields self to the block, and then returns self.
  *  The primary purpose of this method is to "tap into" a method chain,
  *  in order to perform operations on intermediate results within the chain.
  *
- *	(1..10)                  .tap {|x| puts "original: #{x}" }
- *	  .to_a                  .tap {|x| puts "array:    #{x}" }
- *	  .select {|x| x.even? } .tap {|x| puts "evens:    #{x}" }
- *	  .map {|x| x*x }        .tap {|x| puts "squares:  #{x}" }
+ *     (1..10)                  .tap {|x| puts "original: #{x}" }
+ *       .to_a                  .tap {|x| puts "array:    #{x}" }
+ *       .select {|x| x.even? } .tap {|x| puts "evens:    #{x}" }
+ *       .map {|x| x*x }        .tap {|x| puts "squares:  #{x}" }
  *
  */
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]