Created
August 4, 2011 22:12
-
-
Save JEG2/1126431 to your computer and use it in GitHub Desktop.
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
# I see code like this all the time: | |
def get_results | |
if have_results? | |
return results # an Enumerable object | |
else | |
nil | |
end | |
end | |
def process_results | |
if results = get_results | |
results.each do |result| | |
# whatever... | |
end | |
end | |
end | |
# But that can almost always be simplified to: | |
# get_results() not needed. Sometimes will just be [ ]. That's totally OK. | |
def process_results | |
results.each do |result| # works fine on [ ] too | |
# whatever... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment