From: Morton Goldberg Date: 2006-09-12T13:59:11+09:00 Subject: Re: find_all help On Sep 12, 2006, at 12:20 AM, kovax wrote: > Hello, > > I have an array filled with employee objects that are defined like > this: > > Employee = Struct.new(:name, :age) > > I would like to use the find_all method on an array of employee > objects > to find all employee objects with an age > 18. I tried the following > code but I was unsuccessful: > > employees = [] > employees.add Employee.new("joe" , 4) > employees.add Employee.new("sam" , 20) > > employees.select { Employee.age > 18 } > > Any help or pushes in the right direction would be really appreciated. I was tempted to answer that your code is illegal because employing four-year olds is illegal :), but the real answer is Array doesn't support 'add'. In Ruby you use 'push' or '<<'. Further, the form for using 'select' is: a_collection.select { |identifier| } where 'identifier' gets bound successively to elements of 'a_collection'. So try something like: #! /usr/bin/ruby -w Employee = Struct.new(:name, :age) employees = [] employees << Employee.new("joe" , 4) employees << Employee.new("sam" , 20) p employees.select {|e| e.age > 18 } [#] Regards, Morton