Created
October 8, 2009 15:59
-
-
Save bosmacs/205126 to your computer and use it in GitHub Desktop.
This file contains 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
# add list comprehensions to arrays, used like so: | |
# >> (1..25).to_a.comprehend { |x| x**2 if not x % 2 == 0 } | |
# => [1, 9, 25, 49, 81, 121, 169, 225, 289, 361, 441, 529, 625] | |
class Array | |
def comprehend(&block) | |
block ? map(&block).compact : self | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment