Created
March 15, 2009 03:42
-
-
Save logankoester/79296 to your computer and use it in GitHub Desktop.
Element access in an enumerable
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 | |
# 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