Skip to content

Instantly share code, notes, and snippets.

@lukeasrodgers
Created September 18, 2014 19:19
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 lukeasrodgers/3e89ed8bfccc8b675dbf to your computer and use it in GitHub Desktop.
Save lukeasrodgers/3e89ed8bfccc8b675dbf to your computer and use it in GitHub Desktop.
ruby take_select
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