diff options
author | stomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-30 18:17:55 +0000 |
---|---|---|
committer | stomar <stomar@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-30 18:17:55 +0000 |
commit | 8bce215fa2a9ada3b57b2b37b43768edab09c56c (patch) | |
tree | 516b87a2c1920af2b5fee2c94cb4a8bc64914c9b /object.c | |
parent | e4cc791f87700ea6d59d358e2f688fcc85c45676 (diff) | |
download | ruby-8bce215fa2a9ada3b57b2b37b43768edab09c56c.tar.gz |
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
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -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}" } * */ |