IRB.start没有开始

时间:2015-10-11 21:02:18

标签: ruby gem irb

我有一些运行IRB.start的代码(来自gem内部)

但是,我在magic-file.rb中收到此错误“没有这样的文件或目录@ rb_sysopen - console”

/Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb/magic-file.rb:7:in `initialize': No such file or directory @ rb_sysopen - console (Errno::ENOENT)
    from /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb/magic-file.rb:7:in `open'
    from /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb/magic-file.rb:7:in `open'
    from /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb/input-method.rb:100:in `initialize'
    from /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb/context.rb:84:in `new'
    from /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb/context.rb:84:in `initialize'
    from /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb.rb:426:in `new'
    from /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb.rb:426:in `initialize'
    from /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb.rb:381:in `new'
    from /Users/you/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/irb.rb:381:in `start'
    from /Users/you/projects/mygem/lib/mygem/commands.rb:20:in `console'

1 个答案:

答案 0 :(得分:1)

我明白了!通过查看代码:

我能够确定IRB检查ARGV,以便您可以将命令行上的IRB args传递给您调用IRB.start的任何脚本。

但是因为我试图创建一个rake任务来启动一个控制台,我方便地预加载了我的库,我的命令行是:

rake console

并且IRB正在尝试加载文件'console',因为它假定第一个没有连字符的arg是要运行的脚本。有点烦人。 (IRB.start应该将args作为方法arg来避免这种紧耦合。)

我设法通过在我的IRB.start:

之前添加它来修复它
ARGV.clear

更新:自从请求以来,这就是ARGV的确切位置: