Created
June 17, 2015 12:45
-
-
Save 0x0dea/8120823ed2e9a8f8dab8 to your computer and use it in GitHub Desktop.
Improved Enumerable#all?
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
module Enumerable | |
def all? p = nil | |
pred = block_given? ? proc : -> x { p ? p === x : x } | |
each { |obj| return false unless pred[obj] } | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment