Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created August 4, 2011 22:12
Show Gist options
  • Save JEG2/1126431 to your computer and use it in GitHub Desktop.
Save JEG2/1126431 to your computer and use it in GitHub Desktop.
# 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