Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tap vs Local Variables
def level_descriptions=(input)
write_attribute(:levels_description, input).tap do |_result|
flush_cache :levels_description
end
end
# same number of lines, one less method call, one less block, but pretty much the same as
# far as I'm concerned.
def level_descriptions=(input)
result = write_attribute(:levels_description, input)
flush_cache :levels_description
result
end
# effectively the same behavior barring exceptions, has no variables
# probably harder for folks to read/understand, I would prefer either the two above
def level_descriptions=(input)
write_attribute(:levels_description, input) ensure flush_cache :levels_description
end
# bottom line, I see no compelling reason to choose tap over a local variable or vice-versa.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.