Skip to content

Instantly share code, notes, and snippets.

@pxlpnk
Last active December 25, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pxlpnk/7007745 to your computer and use it in GitHub Desktop.
Save pxlpnk/7007745 to your computer and use it in GitHub Desktop.
__FILE__ == $0 with symlinks?
~❯ ls -lah
total 8.0K
drwxr-xr-x 4 at 136 Oct 16 15:26 .
drwxr-xr-x 16 at 544 Oct 16 15:22 ..
-rw-r--r-- 1 at 86 Oct 16 15:26 luke.rb
lrwxr-xr-x 1 at 7 Oct 16 15:26 yoda.rb -> luke.rb
~❯ cat luke.rb
p [__FILE__, $0]
if __FILE__ == $0
puts '__FILE__ == $0'
else
puts 'NOT'
end
~❯ ruby luke.rb
["luke.rb", "luke.rb"]
__FILE__ == $0
~❯ ruby yoda.rb
["yoda.rb", "yoda.rb"]
__FILE__ == $0
~❯ ruby --version
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
Update
---
lrwxr-xr-x 1 at 27 Oct 16 15:39 anakin.rb -> /Users/at/trash/asd/luke.rb
~/trash/asd❯ ruby subdir/anakin.rb
["subdir/anakin.rb", "subdir/anakin.rb"]
__FILE__ == $0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment