Skip to content

Instantly share code, notes, and snippets.

@oriolgual
Created July 6, 2012 10:09
Show Gist options
  • Save oriolgual/3059354 to your computer and use it in GitHub Desktop.
Save oriolgual/3059354 to your computer and use it in GitHub Desktop.
to tap or not to tap?
def do_it(ids)
contacts = contact_finder(ids)
contacts = contacts.my_nice_scope if should_apply_nice_scope?
contacts
end
def do_it(ids)
contact_finder(ids).tap do |contacts|
return contacts.my_nice_scope if should_apply_nice_scope?
end
end
@oriolgual
Copy link
Author

Is returning inside tap really that bad? :P

@txus
Copy link

txus commented Jul 6, 2012

I like the no_tap version, because it communicates everything at a glance. You're fetching contacts, then maybe filtering them or not, and returning them. The second version is way more complicated to understand at a glance (and has the same LOC).

@mrcasals
Copy link

mrcasals commented Jul 6, 2012

+1 to the no_tap version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment