Skip to content

Instantly share code, notes, and snippets.

@seki
Last active December 15, 2015 05:49
Show Gist options
  • Save seki/5212308 to your computer and use it in GitHub Desktop.
Save seki/5212308 to your computer and use it in GitHub Desktop.
module Enumerable
def slice(nth, len)
return to_enum(__method__, nth, len) unless block_given?
each do |*arg|
break if len <= 0
if nth >= 1
nth -= 1
next
end
len -= 1
yield(*arg)
end
end
end
if __FILE__ == $0
enum = (0..10000000000).each_with_index
p enum.slice(100, 100).find_all {|k, v| v % 15 == 0}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment