From: "David A. Black" Date: 2009-09-16T10:35:20+09:00 Subject: Re: range Hi -- On Wed, 16 Sep 2009, Glenn Jackman wrote: > At 2009-09-15 06:23PM, "Rob Biedenharn" wrote: >> On Sep 15, 2009, at 6:11 PM, Sebastian Hungerecker wrote: >>> Am Mittwoch 16 September 2009 00:06:21 schrieb Re BR: >>>> how can I convert a string '20-30' to a instance range object 20..30 >>> >>> first, last = '20-30'.split("-") >>> first.to_i .. last.to_i >>> #=> 20..30 >>> >>> HTH, >>> Sebastian >> >> Or: >> >> string="20-30" >> Range.new(*(string.split('-',2).map{|s|s.to_i})) > > Or: > range = string.match(/(\d+)-(\d+)/) and ($1.to_i .. $2.to_i) Or: range = Range.new(*str.scanf("%d-%d")) David -- David A. Black, Director Ruby Power and Light, LLC (http://www.rubypal.com) Ruby/Rails training, consulting, mentoring, code review Book: The Well-Grounded Rubyist (http://www.manning.com/black2)