Skip to content
Better HN
Top
New
Best
Ask
Show
Jobs
Search
⌘K
#tap_if - a new type of conditional for Ruby | Better HN
#tap_if - a new type of conditional for Ruby
(opens in new tab)
(github.com)
2 points
bnorton
13y ago
2 comments
Share
2 comments
default
newest
oldest
bnorton
OP
13y 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.
User.where(:email => email).first.tap_if(:present?) {|user| user.send_update }
bnorton
OP
13y ago
the magic is here:
https://github.com/bnorton/tap_if/blob/master/lib/tap_if.rb
j
/
k
navigate · click thread line to collapse