From 1d3903fbd7d6c83ab2d794a461e95a101a1be085 Mon Sep 17 00:00:00 2001 From: stomar Date: Tue, 30 May 2017 18:17:55 +0000 Subject: 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 --- object.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 270a0a838b..5e74359145 100644 --- a/object.c +++ b/object.c @@ -493,12 +493,12 @@ rb_obj_dup(VALUE obj) /* * call-seq: - * obj.itself -> an_object + * obj.itself -> obj * - * Returns obj. + * 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 obj 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}" } * */ -- cgit v1.2.3