Skip to content

Instantly share code, notes, and snippets.

@logankoester
Created March 15, 2009 03:42
Show Gist options
  • Save logankoester/79296 to your computer and use it in GitHub Desktop.
Save logankoester/79296 to your computer and use it in GitHub Desktop.
Element access in an enumerable
module Enumerable
# Return elements after the first x
def enum_after(x)
a = 0
self.partition{ a += 1; a < (x + 1) }.last
end
# Return elements with keys between x and y
def enum_between(x,y)
self.reject{|(k,v)| k < (x + 1) || (y - 1) < k }
end
def enum_between_inclusive(x,y)
self.reject{|(k,v)| k < x || y < k }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment