简体   繁体   中英

How to set RubyMine's default working directory to the executing .rb program's subdirectory?

In RubyMine, I have a project with many subfolders, each of which contains:

  • One or more standalone single-file executable Ruby programs ( .rb files);
  • An input text file.

In older versions of RubyMine, when running one of the standalone executable programs (via Cmd+Shift+R on my Mac), the default folder in which RubyMine would look for the input file would be the same directory as the.rb file currently being executed -- which worked great.

The code used to read the file is something like:

data = File.readlines('input.txt')

However, after recently updating RubyMine to v2022.3.1, the behavior has changed, such that RubyMines now seems to be looking in the project's root directory for the file, instead of the same subdirectory as the.rb file currently being run. This produces the error:

in `readlines': No such file or directory @ rb_sysopen - input.txt (Errno::ENOENT)

To correct this, I've been going into Run (menu) > Edit Configurations; and in the Edit Configurations dialog, in the configuration that RubyMine auto-created for the current executable file, changing the Working Directory value from the default of the project's root directory, to the subfolder of the current.rb file.

However, this above workaround is annoying, since I need to do it once each for every individual one of the many individual.rb executable files in my project.

My question: How can I configure my project and/or RubyMine itself to go back to the older behavior of defaulting a given.rb file to use its own directory as the default Working Directory, instead of the project's root directory?

(This question and/or its solution might also apply to other JetBrains IDEs such as IntelliJ, since they all seem to work similarly.)

The previous behaviour has been changed with https://youtrack.jetbrains.com/issue/RUBY-29236 . So now yes, the logic is the following:

  1. in case of no Ruby module, project's root will be used
  2. in case of Rails, its home folder
  3. otherwise the module's root

There is no option to change it in RubyMine but you can configure the configuration template using some variable there as Working directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM