I have a Ruby script (say, genrc.rb) that generates a custom rc file (say, ~/.custom_rc). How can I source this file in to the current shell by running the ruby script?
$ ruby genrc.rb
$ # commands from the ~/.custom_rc should be available here
A Ruby script (or any program, for that matter) cannot alter the shell that started it, so you’ll either have to run
source ~/.custom_rc
after running the script, or have the script also output the contents of the file to stdout, in which case you could do
source <(ruby genrc.rb)
or
eval "$(ruby genrc.rb)"
The script could also instead output the path to the written file, and you could do:
source $(ruby genrc.rb)
eval & source) have that power, everything else is a forked process.