Skip to content

Instantly share code, notes, and snippets.

@frosty
Created March 10, 2010 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frosty/327806 to your computer and use it in GitHub Desktop.
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)
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