diff options
author | davidflanagan <davidflanagan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-08 08:12:59 +0000 |
---|---|---|
committer | davidflanagan <davidflanagan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-08 08:12:59 +0000 |
commit | 68ddfec346331004e4b4a5374ee4e60c756d7d5c (patch) | |
tree | 42513003bbd5d173e3b9fd17f596420e2202d377 /object.c | |
parent | 453889cf0ccc2d5676f49893e670fc611e4ae08c (diff) | |
download | ruby-68ddfec346331004e4b4a5374ee4e60c756d7d5c.tar.gz |
* object.c: improve docs for Object.tap
* ChangeLog: fix bogus dates on my previous entries
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -448,9 +448,15 @@ rb_obj_is_kind_of(VALUE obj, VALUE c) * call-seq: * obj.tap{|x|...} => obj * - * Returns the receiver after executing the block given. Its main - * purpose is to be inseted in the method chain. - * + * Yields <code>x</code> to the block, and then returns <code>x</code>. + * 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.inspect}"} + * .to_a .tap {|x| puts "array: #{x.inspect}"} + * .select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"} + * .map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"} + * */ VALUE |