Created
March 9, 2018 14:37
-
-
Save soulcutter/cd01376def3bca33f08b99d2297bf984 to your computer and use it in GitHub Desktop.
Tap vs Local Variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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