Detect `RBENV_DIR` properly from file argument to `ruby`
I believe there are 2 weird behaviour relating to RBENV_DIR. This should fix both 2.
- file argument does not follow symlink (yyuu/pyenv#404)
- file argument works weirdly if first argument doesn't contain
/(yyuu/pyenv#479)
Both can be reproduced with the following setup.
$ mkdir -p ./foo
$ echo 2.2.3 > ./foo/.ruby-version
$ echo 'puts(RUBY_DESCRIPTION)' > ./foo/test.rb
$ mkdir -p ./foo/bar
$ echo jruby-9.0.0.0 > ./foo/bar/.ruby-version
$ ln -sf ${PWD}/foo/test.rb ./foo/bar/
If the first file argument to ruby interpreter is a symlink, it'd be better to follow the link.
$ ruby ./foo/test.rb
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ ruby ./foo/bar/test.rb
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 OpenJDK 64-Bit Server VM 25.72-b05 on 1.8.0_72-internal-b05 +jit [linux-amd64]
RBENV_DIR just not working if the first file argument doesn't contain /.
$ cd ./foo
$ ruby test.rb
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ ruby test.rb ./bar/test.rb
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 OpenJDK 64-Bit Server VM 25.72-b05 on 1.8.0_72-internal-b05 +jit [linux-amd64] # <-- this would be better to be 2.2.3
Resolved conflict.
Thank you for the implementation, explanation, and the ensuing discussion, but I remained unconvinced that this is a change I want in rbenv, and in the interest of keeping rbenv stable, I'm going to close this. Furthermore, I stopped resolving symlinks in most places within rbenv: https://github.com/rbenv/rbenv/pull/1428
I believe that if you call ruby /path/to/file.rb, the /path/to/.ruby-version file should be respected and the actual destination of the /path/to/file.rb symlink shouldn't really matter.