Skip to content

Instantly share code, notes, and snippets.

@reu
Created April 7, 2010 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reu/358431 to your computer and use it in GitHub Desktop.
Save reu/358431 to your computer and use it in GitHub Desktop.
# Classic approach
def check_for_truth
has_at_least_one_true = false # ewwww temp var
[false, false, true].each do |option|
has_at_least_one_true = option
end
has_at_least_one_true
end
# Rubysh approach
def check_for_truth
[false, false, true].inject(false) {|answer, option| answer || option }
end
# http://ruby-doc.org/core/classes/Enumerable.html#M003129
# http://blog.jayfields.com/2008/03/ruby-inject.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment