现象是 rails console 里面 tab 的时候会触发 IRB_EXIT,让人很恼火,错误信息如下:
.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:83:in `throw': uncaught throw :IRB_EXIT (ArgumentError)
from /home/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:83:in `irb_exit'
from /home/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/context.rb:265:in `exit'
from /home/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/extend-command.rb:23:in `irb_exit'
from /home/john/.rvm/gems/ruby-1.9.2-p290/gems/simplecov-0.6.0/lib/simplecov/defaults.rb:52:in `block in <top (required)>'
/home/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/completion.rb:161:in `block (2 levels) in <module:InputCompletor>': can't convert Regexp to String (TypeError)
看起来是 completion.rb 的问题,源码如下:
ObjectSpace.each_object(Module){|m|
begin
name = m.name
rescue Exception
name = ""
end
next if name != "IRB::Context" and
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name # <- Line 161
candidates.concat m.instance_methods(false).collect{|x| x.to_s}
}
candidates.sort!
candidates.uniq!
我将 name 改为 name.to_s,问题可以解决,但是不明白为什么会有这个 bug,而且似乎在 irb 中没有这个现象,有人遇到过类似的情况么?