Last active
June 6, 2019 20:36
-
-
Save awesome/839b6b9b645d2ff74ff75e9db225a2c9 to your computer and use it in GitHub Desktop.
How to get the name of the current file with directory filepath using ruby. @awesome #soawesomeman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $ ruby -v | |
# ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18] | |
# $ pwd | |
# /Users/dev/Documents/Github/Gists/awesome/ | |
# $ echo "puts File.expand_path(__FILE__)" > how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb | |
# $ echo "puts File.absolute_path(__FILE__)" >> how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb | |
# $ cat how-to-get-the-name-of-the-current-file-with-directory-filepath.rb | |
# puts File.expand_path(__FILE__) | |
# puts File.absolute_path(__FILE__) | |
# $ ruby how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb | |
# /Users/dev/Documents/Github/Gists/awesome/how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb | |
# /Users/dev/Documents/Github/Gists/awesome/how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb | |
puts File.expand_path(__FILE__) | |
puts File.absolute_path(__FILE__) | |
# docs: | |
# https://ruby-doc.org/core-2.0.0/File.html#method-c-expand_path | |
# https://ruby-doc.org/core-2.0.0/File.html#method-c-absolute_path | |
# https://www.rubydoc.info/github/rubyworks/facets/Binding#__FILE__-instance_method | |
# http://ruby-doc.org/docs/keywords/1.9/Object.html#method-i-__FILE__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment