I want to make a generic method that will take either a single object or collection, and then return an array of id’s, and the actual id to take from the object/collection will also be passed in as a parameter.
Example:
a = []
a << get_ids("car_id", some_object)
a << get_ids("user_id", some_collection)
def self.get_ids(id_name, obj)
# ??
end
This needs metaprogramming I know, but how do I figure out if its a collection or not?
do I send a message to check if “id_name” is a property?
Also, I currently need this type of functionality, so I thought of making it generic so I can re-use it. Does it have any major performance implications?
Alternatively,