1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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}.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
stomar 2017-05-30 18:17:55 +00:00
parent e4cc791f87
commit 8bce215fa2

View file

@ -493,12 +493,12 @@ rb_obj_dup(VALUE obj)
/*
* 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, VALUE obj)
/*
* 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 c)
/*
* 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}" }
*
*/