I need to convert a passed in argument (single object or collection) to an Array. I don't know what the argument is. If it is an Array already, I want to leave it, otherwise create a one-element array from it. I'm looking to allow both method(:objs => obj)
and method(:objs => [obj1, obj2])
This seems to be the best way (Array.to_a returns self):
arg = arg.to_a
But the ruby docs say Object.to_a
will soon be obsolete. Is there convenient replacement?
Anything more succinct than this?
arg = arg.respond_to?(:to_a) ? arg.to_a : [arg]