File.join oddity ?

From: Johan Holmberg <holmberg@...>
Date: 2004-04-26 16:39:49 UTC
List: ruby-core #2819
Hi !

By accident I called File.join like this:

   File.join("a", [["b"], "c"], "d")     # "a/b/c/d"

and was a rather surprised by the result. This behaviour of
"flattening" the arguments seem rather un-intuitive to me.
Even more in this case:

   arr = [["b"], "c"]
   arr.push arr                  # to get circular
   File.join("a", arr, "d")      # "a/b/c/b/c/[...]/d"


As far as I can see, this is *never* what the user would have
expected (an error would have been more appropriate).

Why does File.join have this extra complexity ?
If this is considered a "feature" I think it should at least be
documented.

Wouldn't it be more natural if File.join only accepted
strings (or "string-like" objects ) as arguments ?

/Johan Holmberg


In This Thread

Prev Next