Created
October 30, 2012 14:01
-
-
Save thomasklemm/3980329 to your computer and use it in GitHub Desktop.
Operations with Ranges
This file contains hidden or 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 Range | |
def end_at(x) | |
Range.new(self.begin, x) | |
end | |
def start_at(x) | |
Range.new(x, self.end) | |
end | |
end | |
# Initial Range | |
range = 1..10 | |
# New end | |
p range.end_at(100) | |
# => 1..100 | |
# New start | |
p range.start_at(5) | |
# => 1..5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment