From: Joel VanderWerf Date: 2009-04-30T04:23:37+09:00 Subject: Re: Finding Matches in Array of Classes 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. > > Rob require 'time' range = Time.parse("2008-1-1")..Time.parse("2009-1-1") results.select {|r| range.include? r.observation_time} -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407