-
-
Save nateberkopec/21f5c4cdf7fc51c6de87 to your computer and use it in GitHub Desktop.
This file contains 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 some_method | |
some_work_that_you_want_the_return_value_of && | |
something_that_should_execute_if_the_above_is_successful | |
end | |
# how would you make some_method return the result of some_work_that_you_want_the_return_value_of | |
# instead of something_that_should_execute_if_the_above_is_successful? | |
def one_idea | |
result = some_work_that_you_want_the_return_value_of | |
something_that_should_execute_if_the_above_is_successful if result | |
result | |
end | |
# but that strikes me as very un-idiomatic | |
def tap_that | |
some_work_that_you_want_the_return_value_of.tap do |result| | |
something_that_should_execute_if_the_above_is_successful if result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment