Skip to content

Instantly share code, notes, and snippets.

@ianbishop
Created May 10, 2012 22:34
Show Gist options
  • Select an option

  • Save ianbishop/2656316 to your computer and use it in GitHub Desktop.

Select an option

Save ianbishop/2656316 to your computer and use it in GitHub Desktop.
Symbol#to_proc map-reduce
# Get total sum of the sizes of each word
words = "Hello World, how are you today?".split(/\s/)
words.map(&:size).inject(&:+)
# => 26
# Validate numerous fields
fields = ["foo", "bar", "tomato", "tomatoes", nil]
valid = !fields.map(&:nil?).inject(&:|)
# => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment