Skip to content

Instantly share code, notes, and snippets.

@nateberkopec
Last active August 29, 2015 14:16
Show Gist options
  • Save nateberkopec/21f5c4cdf7fc51c6de87 to your computer and use it in GitHub Desktop.
Save nateberkopec/21f5c4cdf7fc51c6de87 to your computer and use it in GitHub Desktop.
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