Created
September 18, 2014 19:19
-
-
Save lukeasrodgers/3e89ed8bfccc8b675dbf to your computer and use it in GitHub Desktop.
ruby take_select
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
class Array | |
def take_select n, &block | |
count = 0 | |
res = [] | |
select do |x| | |
r = yield x | |
if r == true | |
count += 1 | |
res << x | |
end | |
break if count >= n | |
end | |
res | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment