What is the best way to convert a Ruby string range to a Range object

Question :

What is the best way to convert a Ruby string range to a Range object,

Answer :

I have some Ruby code which takes dates on the command line in the format:

-d 20080101,20080201..20080229,20080301  

I want to run for all dates between 20080201 and 20080229 inclusive and the other dates present in the list.

I can get the string 20080201..20080229, so is the best way to convert this to a Range instance? Currently, I am using eval, but it feels like there should be a better way.


@Purfideas I was kind of looking for a more general answer for converting any string of type int..int to a Range I guess.

Read More  Find out which colours are in use when using the MFC Feature pack in Office 2007 style

,

Range.new(*self.split("..").map(&:to_i))  

That’s the answer What is the best way to convert a Ruby string range to a Range object, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you

Read More  ActionScript 3.0 sockets can’t reconnect