简体   繁体   中英

Using the -r command line Ruby switch

The -rname Ruby switch can be only used to require something that already exists in Ruby's library, or can I use it to also require from the command line an external file created by me? For example, I'm trying to run a program "loaddemo.rb" with a "loadee.rb" file already required:

ruby -rloadee loaddemo.rb

It doesn't work. What is my mistake here?

You can use it to require other files too but require is a thing, import another one. To require something, it has to be in your load path too.

Try -I . to insert the current directory in your load path if loadee.rb is there

ruby -r loadee -I . loaddemo.rb

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