From: James Edward Gray II Date: 2006-08-14T04:03:19+09:00 Subject: Re: Search objects On Aug 13, 2006, at 12:54 PM, Dark Ambient wrote: > I can use some help here: > > I've set up this class and objects and would like to "search" it > similar to the way I would search a database. At this point I'm not > concerned with adding regex for more liberal searches. > Any suggestions ? > > > > class Composer > def initialize( lname, country ) > @lname = lname > @country = country > end > attr_accessor(:lname, :country) > end > > comp1 = Composer.new("Beethoven", "Germany") > comp2 = Composer.new("DeFalla", "Spain") > comp3 = Composer.new("Debussy", "France") Well, if we had those composers in an Array, we could use normal iterators like: composers.find { |c| c.country == "Germany" } and: composers.select { |c| c.lname =~ /^De/ } Hope that gives you some fresh ideas. James Edward Gray II