File.expand_path(file_name [, dir_string] Converts a pathname to an absolute pathname - according to rdocs.
When you write File.expand_path('../btree', __FILE__) it will return "#{Dir.pwd}/btree". For example, if you are in the /tmp directory, File.expand_path('../btree', __FILE__) returns “/tmp/btree”.
Let’s take some other examples:
File.expand_path('btree', 'f')
=> "/tmp/f/btree"
File.expand_path('btree', __FILE__) # If you are in IRB
=> "/tmp/(irb)/btree"
File.expand_path(__FILE__)
=> "/tmp/(irb)"
File.expand_path('../btree', __FILE__)
=> "/tmp/btree"
The last line returns /tmp/btree. At first you need to consider the second argument. It takes you to the /tmp/(irb). Then the first argument takes you to the parent directory of (irb), which is /tmp/ again. This way expand_path ended up returning the /tmp/btree/.
Coming to the second part of your question, …/btree is a valid directory.
File.expand_path('.../btree')
=> "/tmp/.../btree"
I don’t know about Windows or Mac, but on GNU/Linux (especially I am using the XFS file system and my ramdisk) you can create a directory called ‘…’, ‘?’, ‘<’, ‘|’ etc (except unescaped /). Yes, really!