Array splats (the *p) there are only valid as the last argument in the argument list, since it means "collect all the rest of the arguments passed to the method into an array p".
Just remove d from the method signature, and in your method, just set d = p.pop and it'll work. Or, move d before *p.