From: Todd Benson Date: 2009-04-30T04:21:54+09:00 Subject: Re: Finding Matches in Array of Classes On Wed, Apr 29, 2009 at 2:03 PM, Rob Redmon wrote: > > I have an ActiveRecord find result. An element's contents look like: > > irb(main):090:0> results[0] > => # station_id: 6, extension_id: 22, disk: 4, archive: 0, updated_on: > "2009-04-15 15:57:16"> > > The class of "observation_time" is: > results[0].observation_time.class > => Time > > > What I'd like to do is find those elements which match on a particular > range of "observation_time". I'm used to Matlab and IDL programming > where one just does something like this: > > indices = where( results.observation_time >= "2008-1-1" and > results.observation_time < "2009-1-1" ) > > What's the ruby way? Obviously, I can't use Array.include? but > something like that would be nice. Depends. This might work (just an example)... d = Time.now e = Time.now + 1 f = Time.now + 2 (d..f).include? e => true Todd