Tap before you squash

Tap is a pretty awesome ruby method I recently discovered.

Let’s say I have the following request:

post  '/api/v1/users/', 
          params.merge(:sig => 

I realize something is screwed and I want to print out the sig before sending. Normally I would actually rewrite my code:

sig = Authentication.calculate(TestAuthData.secret_access_key,params.to_query)
puts "sig = #{sig}"
post  '/api/v1/users/', params.merge(:sig => sig).to_json

That’s a bit annoying. With tap I can just do this:

post  '/api/v1/users/', 
          params.merge(:sig => 
            Authentication.calculate(TestAuthData.secret_access_key,params.to_query).tap{|s| puts "sig = #{s}"}
No TweetBacks yet. (Be the first to Tweet this post)
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

This entry was posted in Software and tagged , , . Bookmark the permalink. Both comments and trackbacks are currently closed.