简体   繁体   中英

Ruby: How to run irb immediately after running ruby file externally?

Is there a way to load a ruby file from terminal, but continue coding dynamically after?

Example:

$ ruby some_file.rb

# ... code from source file ...

and continue coding from here through terminal (in the same fashion as irb)?

The -r flag will require a file when starting IRB:

irb -r /path/to/file

Example:

~$ echo "def hello; puts 'Hello, world!'; end" > hello.rb
~$ irb -r ./hello
001> hello
Hello, world!

See man irb :

-r library     Same as `ruby -r'.  Causes irb to load the library using require.

Run irb, and load the file from within irb.

irb> load "some_file.rb"

If you want to do that everytime, then write it in a file named .irbrc .

.irbrc

load "some_file.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