From: Marcin Grzywaczewski Date: 2007-09-03T06:15:58+09:00 Subject: Re: extract a range start/end? ------=_Part_12383_22871931.1188767753924 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2007/9/2, Wilson Bilkovich : > > On 9/2/07, Marcin Grzywaczewski wrote: > > 2007/9/2, Michael Linfield : > > > > > > if i have a list of dates in an array such as: > > > > > > 4/2/07 > > > 4/3/07 > > > 4/4/07 > > > 4/5/07 > > > 4/6/07 > > > 4/7/07 > > > 4/8/07 > > > ect. > > > > > > how would i..based on option parse..pull a starting point and end > point > > > of to extract that data range. > > > > > > IE: > > > > > > opts = OptionParser.new do |opts| > > > opts.on("-s", "--startdate", "What start date to use." do |i| > > > #code to determine to use the starting date > > > end > > > > > > # the same would apply to an --enddate > > > > > > any ideas? > > > > > > i was thinking i could possibly create a new range depending on what > the > > > user input was by doing > > > > > > require 'date' > > > results = [] > > > > > > (Date.new(2007,4,1)..Date.new(2007,4,8)).each {|r| res << r} > > > but then how would i match that against the original dates for the > data? > > > > > > feel free to give me any thoughts. > > > > > > -Thanks > > > -- > > > Posted via http://www.ruby-forum.com/. > > > > > > I think that range operates on numbers, and method "to_i" casts class to > > number, so your class should have specific method "to_i". > > > > From rdoc: > Ranges can be constructed using objects of any type, as long as > the objects can be compared using their <=> operator and they > support the succ method to return the next object in sequence. > > In practice, that usually means 'Anything that has Enumerable as an > ancestor' Oh, my bad. Sorry :)... Yours, Killavus. ------=_Part_12383_22871931.1188767753924--