Settings

Theme

#tap_if - a new type of conditional for Ruby

github.com

2 points by bnorton 13 years ago · 2 comments

Reader

bnortonOP 13 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.

User.where(:email => email).first.tap_if(:present?) {|user| user.send_update }

bnortonOP 13 years ago

the magic is here: https://github.com/bnorton/tap_if/blob/master/lib/tap_if.rb

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection