How do I get an array of object ids?


#1

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?


#2

Hi Ray,

Try this: a = bs.collect { |b| b.id }

Ray B. 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?


#3

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.