I have a .rb script that access and edit all .txt files in same directory with Dir.glob('*.txt') do |rb_file|
If I call it from terminal ruby myscript.rb
all works fine.
Then I made an executable, launched with double click on Mac OS, as explained at this and this answers. I started file with #!/usr/bin/env ruby
, gave permissions chmod +x myscript.rb
, and opened it with terminal.
Ruby is working but when I try to access files in the same directory, the script can't find them. In fact, the script look for these files in /Users/myname directory.
How can I access the original directory where the double clicked file is?
I tried with ./
without success.
Absolute path is not an option, unless programmatically retrieved.
Thank you