Bug #555: method_missing in Gem module removes some necessary methods
http://redmine.ruby-lang.org/issues/show/555

Author: Akira Matsuda
Status: Open, Priority: Normal

I found something strange in Ruby 1.9 bundled Rubygems(gem_prelude.rb).

(1) there's a method named default_dir in Gem module, which returns a certain directory name
 Gem.default_dir
 #=> "/Users/matsuda/ruby/lib/ruby/gems/1.9.0"

(2) call a missing method on Gem module to make a method_missing call
 Gem.foo
 NoMethodError: undefined method `foo' for Gem:Module
     from gem_prelude.rb:192:in `method_missing'
     from (irb):12
     from /Users/matsuda/ruby/bin/irb19:12:in `<main>'

(3) method_missing undefs Gem::GEM_PRELUDE_METHODS.each methods inside Gem.method_missing -> QuickLoader.load_full_rubygems_library

(4) Gem.default_dir still alives
 Gem.default_dir
 #=> "/Users/matsuda/ruby/lib/ruby/gems/1.9.0"

(5) invoke method_missing again
 Gem.foo
 /Users/matsuda/ruby/lib/ruby/1.9.0/rubygems.rb:82: warning: already initialized constant MUTEX
 /Users/matsuda/ruby/lib/ruby/1.9.0/rubygems.rb:84: warning: already initialized constant RubyGemsPackageVersion
 /Users/matsuda/ruby/lib/ruby/1.9.0/rubygems.rb:89: warning: already initialized constant WIN_PATTERNS
 /Users/matsuda/ruby/lib/ruby/1.9.0/rubygems.rb:742: warning: already initialized constant MARSHAL_SPEC_DIR
 /Users/matsuda/ruby/lib/ruby/1.9.0/rubygems.rb:744: warning: already initialized constant YAML_SPEC_DIR
 NoMethodError: undefined method `foo' for Gem:Module
     from gem_prelude.rb:192:in `method_missing'
     from (irb):14
     from /Users/matsuda/ruby/bin/irb19:12:in `<main>'

(6) Gem.default_dir disappears!
 Gem.default_dir
 NameError: undefined method `default_dir' for `Gem'
     from gem_prelude.rb:78:in `undef_method'
     from gem_prelude.rb:78:in `block in singletonclass'
     from gem_prelude.rb:77:in `each'
     from gem_prelude.rb:77:in `singletonclass'
     from gem_prelude.rb:76:in `load_full_rubygems_library'
     from gem_prelude.rb:191:in `method_missing'
     from (irb):15
     from /Users/matsuda/ruby/bin/irb19:12:in `<main>'

I noticed that some gems don't work well on Ruby 1.9 because of this behavior.

Ruby version: revision 19146
gem -v: 1.2.0.1824


----------------------------------------
http://redmine.ruby-lang.org