At least in Ruby 1.9.3, both usages of the join
method seem to be equivalent. Under the hood, the elements of an array are join
ed to the path recursively, with special protection against infinite recursion.
Therefore, this works fine:
File.join 'a', ['b', ['c']]
One might argue that the purpose of the splat operator is to eliminate the recursion. The problem is that this:
File.join 'a', *['b', ['c']]
Is equivalent to this:
File.join 'a', 'b', ['c']
In order to eliminate the recursion, you have to flatten
the array and then splat it:
File.join 'a', *['b', ['c']].flatten
In the context of a parameter list, the splat operator "removes" the brackets of an array, so to speak. It results in this:
# File.join receives 3 strings as parameters
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
As opposed to this:
# File.join receives 2 parameters, one string and one array of strings
$:.unshift File.join(File.dirname(__FILE__), ['..', 'lib'])
More information about the splat operator.