IRB的IRB模拟-i

Col*_*nic 9 ruby irb

我想使用IRB运行脚本然后给我一个交互式提示.我python -i xy.py在Python中执行此操作,但irb xy.rb在执行后退出.

> python --help

-i    When a script is passed as first argument or the -c option is
      used, enter interactive mode after executing the script or the
      command
Run Code Online (Sandbox Code Playgroud)

Ash*_*ams 9

irb -r xy.rb
Run Code Online (Sandbox Code Playgroud)

在给出正常的IRB提示之前,它只需要提到的文件.

  • 但请记住,使用`-r`或`require`将无法访问脚本的局部变量,即使它们是在顶级执行环境中定义的. (4认同)
  • 顺便说一句,从ruby 1.9开始,你需要在所需文件的前面添加路径:`irb -r./ xy.rb` (2认同)