There are actual differences between return l and return *l ; it helps to know what to look for.
An important difference is that it makes a copy of the array or materialized Enumerator - in all cases a new array is returned.
def x(l) return *l end p = ["hello"] q = x(p) q[0] = "world"
Another difference is that the splat operator will force nil to an empty array and will force other values ββ(non-Array / Enumerator) to an array of one element - again, in all cases, a new array is returned.
r = x(nil) # r -> [] s = x("one") # s -> ['one']
Thus, the use of return *l has subtle consequences, which, we hope, are fairly well described in the documentation of the method or are otherwise not βsurprisingβ in use.
user2864740
source share