Hi,
I just updated everything through homebrew to install Ruby 2.3.0 and noticed that rbenv rehash throws this error:
/Users/kaikuchn/.rbenv/versions/2.3.0/lib/ruby/2.3.0/ostruct.rb:176:in `respond_to_missing?': undefined method `key?' for nil:NilClass (NoMethodError)
from /Users/kaikuchn/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:381:in `respond_to?'
from /Users/kaikuchn/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:381:in `init_with'
[ ... ]
from /Users/kaikuchn/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in `accept'
from /Users/kaikuchn/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/nodes/node.rb:38:in `to_ruby'
from /Users/kaikuchn/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych.rb:253:in `load'
from /Users/kaikuchn/.rbenv/plugins/bundler/etc/rbenv.d/bundler/rehash.rb:267:in `block in build_ruby_profiles'
from /Users/kaikuchn/.rbenv/plugins/bundler/etc/rbenv.d/bundler/rehash.rb:266:in `open'
from /Users/kaikuchn/.rbenv/plugins/bundler/etc/rbenv.d/bundler/rehash.rb:266:in `open'
from /Users/kaikuchn/.rbenv/plugins/bundler/etc/rbenv.d/bundler/rehash.rb:266:in `build_ruby_profiles'
from /Users/kaikuchn/.rbenv/plugins/bundler/etc/rbenv.d/bundler/rehash.rb:455:in `<main>'
rbenv version is 1.0.0 and ruby-build version 20151225
It looks like Ruby 2.3.0 has trouble loading OpenStructs from the ruby_profiles.yml file?
The implementation of OpenStruct changed, it now has a #respond_to_missing? method which references @table. That instance variable seems to be nil and causes the error.
As I now realize, this isn't a fault with rbenv, but rather with Psych.. Check this out:
irb(main):061:0> yaml = Psych.dump(OpenStruct.new(ruby_version: [2, 3, 0]))
=> "--- !ruby/object:OpenStruct\ntable:\n :ruby_version:\n - 2\n - 3\n - 0\n"
irb(main):062:0> Psych.load(yaml)
NoMethodError: undefined method `key?' for nil:NilClass
from /Users/kkuchenbecker/.rbenv/versions/2.3.0/lib/ruby/2.3.0/ostruct.rb:176:in `respond_to_missing?'
from /Users/kkuchenbecker/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:381:in `respond_to?'
[ ... ]
from /Users/kkuchenbecker/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/visitors/to_ruby.rb:32:in `accept'
from /Users/kkuchenbecker/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych/nodes/node.rb:38:in `to_ruby'
from /Users/kkuchenbecker/.rbenv/versions/2.3.0/lib/ruby/2.3.0/psych.rb:253:in `load'
from (irb):62
from /Users/kkuchenbecker/.rbenv/versions/2.3.0/bin/irb:11:in `<main>'
I'll create this issue anyway since people are likely to report this here..
Edit: I've now reported this issue https://bugs.ruby-lang.org/issues/11884
Thanks for reporting, but rbenv doesn't have any code in Ruby, and thus can't generate Ruby stack traces. It's all bash script.
Your stack trace comes from rbenv-bundler plugin, which is a known culprit for many kinds of bugs. You should uninstall it, rm -rrbenv root/shims, and try rehash again.
Oh! Thanks for pointing that out.
I removed the plugin and I'm not missing it (nor the stack trace it produced :smile: ).
I'll then close this issue since it has nothing to do with rbenv. Thank you for your quick response and your awesome work!
Just incase this issues comes up in search results for people having the same/similar issue, I also had this but had been installed through homebrew - stack trace included /usr/local/Cellar/rbenv-bundler/0.99/etc/rbenv.d/bundler/rehash.rb:267:in 'block in build_ruby_profiles' opposed to within .rbenv.
brew uninstall rbenv-bundlerrm -rrbenv root/shimsrbenv rehashEnded up here via google. Thanks.
If you've got rbenv-bundler installed and don't want to remove it, you can switch it off with rbenv bundler off.
@dannysmith Thanks for the rbenv bundler off tip.
For me, the fix was:
brew update && brew upgrade
rm -rf `rbenv root`/shims
rbenv bundler off
rbenv rehash
Most helpful comment
Just incase this issues comes up in search results for people having the same/similar issue, I also had this but had been installed through homebrew - stack trace included
/usr/local/Cellar/rbenv-bundler/0.99/etc/rbenv.d/bundler/rehash.rb:267:in 'block in build_ruby_profiles'opposed to within.rbenv.brew uninstall rbenv-bundlerrm -rrbenv root/shimsrbenv rehash