ruby - Array of IDs to array of function results -


i have code

def objects(ids)   array = []    ids.each |id|     array << object(id) # => #<object[id]>   end    array end  objects([1, 2, 3]) # => [#<object1>, #<object2>, #<object3>] 

it seems there should cleaner way this. can help?

edit works

[1, 2, 3].map |id|   object(id) end 

original go way:

[1, 2, 3].map(&:object_id) # => [3, 5, 7]  def objects(ids)   ids.map(&:object_id) end  objects([1, 2, 3]) # => [3, 5, 7] 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -