TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

#tap_if - a new type of conditional for Ruby

2 pointsby bnortonover 12 years ago

2 comments

bnortonover 12 years ago
Instead of assigning a variable or bloating the length of your statements, use this method to to return the caller and only execute the block if the condition passes.<p>User.where(:email =&#62; email).first.tap_if(:present?) {|user| user.send_update }
bnortonover 12 years ago
the magic is here: <a href="https://github.com/bnorton/tap_if/blob/master/lib/tap_if.rb" rel="nofollow">https://github.com/bnorton/tap_if/blob/master/lib/tap_if.rb</a>