If a = object, then a[:id] => 11 (ie, the primary key value of object. But if bs = [ object1, object2], then bs.each { |b| = b[:id] } => bs What I want is an array of the object ids? Suggestions?
Hi Ray, Try this: a = bs.collect { |b| b.id } Ray Baxter wrote:> If a = object, then a[:id] => 11 (ie, the primary key value of object. > > But if bs = [ object1, object2], then bs.each { |b| = b[:id] } => bs > > What I want is an array of the object ids? > > Suggestions?-- Posted via http://www.ruby-forum.com/.
I don''t quite follow your example, but if you want a method which copes with either a single object, or an array of objects, this should work: def object_ids(*objects) objects.flatten.collect { |o| o.id } end -Jonny. -- Posted via http://www.ruby-forum.com/.