Created
March 10, 2010 12:11
-
-
Save frosty/327806 to your computer and use it in GitHub Desktop.
Convert a string representation of a range into a range (e.g. "22..47" becomes 22..47)
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
class String | |
def to_r | |
ends = self.split('..').map{|d| Integer(d)} | |
if ends.size > 1 | |
ends[0]..ends[1] | |
else | |
ends[0] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment