I have some code that runs IRB.start (from inside a gem)
However, I get this error in magic-file.rb "No such file or directory @ 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'
I figured it out! By looking through the code:
I was able to determine that IRB checks ARGV so that you can pass IRB args on the commandline to whatever script you're invoking IRB.start in.
But since I was trying to create a rake task to start a console with my libraries preloaded for convenience, my command line was:
rake console
And IRB was trying to load the file 'console', because it assumes the first arg without a hyphen is a script to run. Kind of annoying. (IRB.start should take args as a method arg to avoid this tight coupling.)
I managed to fix it by adding this before my IRB.start:
ARGV.clear
UPDATE: Since it was requested, here's exactly where ARGV is used:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With