Why not something like this:
def list(*projects) projects.join(', ') end
Then you can call it with as many arguments as you like
list('a') #=> "a" list('a','b') #=> "a, b" arr = %w(abcdefg) list(*arr) #=> "a, b, c, d, e, f, g" list(arr,'h','i') #=> "a, b, c, d, e, f, g, h, i"
Splat (*) automatically converts all arguments to an array, this will allow you to pass an array and / or string without any problems. This will work great with other objects.
list(1,2,'three',arr,{"test" => "hash"})
Thanks @Stefan and @WandMaker for pointing Array#join can handle nested arrays
engineersmnky
source share