Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

AS guide: explains Object#tap

  • Loading branch information...
commit ae44ed59082d7d2c7db32dd93611a16a41c84e13 1 parent ee7487e
@fxn fxn authored
Showing with 18 additions and 0 deletions.
  1. +18 −0 railties/guides/source/active_support_overview.textile
View
18 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+
Please sign in to comment.
Something went wrong with that request. Please try again.