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?
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 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?
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs