aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2009-07-12 01:58:28 +0200
committerXavier Noria <fxn@hashref.com>2009-07-12 01:58:28 +0200
commitae44ed59082d7d2c7db32dd93611a16a41c84e13 (patch)
treedf4a5ba4cefc0e14d157a36575e5f8218ed4f1fc /railties/guides/source
parentee7487e46abbdf195f398922d5b05dc1f5b5d08f (diff)
downloadrails-ae44ed59082d7d2c7db32dd93611a16a41c84e13.tar.gz
rails-ae44ed59082d7d2c7db32dd93611a16a41c84e13.tar.bz2
rails-ae44ed59082d7d2c7db32dd93611a16a41c84e13.zip
AS guide: explains Object#tap
Diffstat (limited to 'railties/guides/source')
-rw-r--r--railties/guides/source/active_support_overview.textile18
1 files changed, 18 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_overview.textile b/railties/guides/source/active_support_overview.textile
index 2248ba33c3..e7751b32b1 100644
--- a/railties/guides/source/active_support_overview.textile
+++ b/railties/guides/source/active_support_overview.textile
@@ -84,6 +84,24 @@ By definition all objects are +duplicable?+ except +nil+, +false+, +true+, symbo
WARNING. Using +duplicable?+ is discouraged because it depends on a hard-coded list. Classes have means to disallow duplication like removing +dup+ and +clone+ or raising exceptions from them, only +rescue+ can tell.
+h4. +tap+
+
++Object#tap+ exists in Ruby 1.8.7 and 1.9, and it is defined by Active Support for previous versions. This method yields its receiver to a block and returns it.
+
+For example, the following class method from +ActionDispatch::TestResponse+ creates, initializes, and returns a new test response using +tap+:
+
+<ruby>
+def self.from_response(response)
+ new.tap do |resp|
+ resp.status = response.status
+ resp.headers = response.headers
+ resp.body = response.body
+ end
+end
+</ruby>
+
+See also +Object#returning+ in "Extensions to All Objects FIX THIS LINK":FIXME.
+
h4. +metaclass+