From: Shugo Maeda Date: 2011-11-24T13:30:41+09:00 Subject: [ruby-core:41278] [ruby-trunk - Bug #5657][Rejected] Constants in included modules aren't visible when defining classes with Class.new Issue #5657 has been updated by Shugo Maeda. Status changed from Open to Rejected Assignee set to Shugo Maeda Gary Bernhardt wrote: > In that case, I think that this can be safely closed. Thanks for your confirmation. ---------------------------------------- Bug #5657: Constants in included modules aren't visible when defining classes with Class.new http://redmine.ruby-lang.org/issues/5657 Author: Gary Bernhardt Status: Rejected Priority: Normal Assignee: Shugo Maeda Category: Target version: ruby -v: - I define two classes that include a module. One is defined with `class`, one is defined with `Class.new`. I expect both to be able to reference constants in the included module. The `class` one can, but the `Class.new` one can't. Reproducing code: module X module Y end end class Class1 include X def self.f # Works: Y is printed p Y end end Class2 = Class.new do include X def self.f # Fails: "uninitialized constant Y" p Y end end Class1.f Class2.f It works with 1.9.2: $ ruby -v ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0] $ ruby bug.rb X::Y X::Y but not 1.9.3-p0: $ ruby -v ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0] $ ruby bug.rb X::Y bug.rb:18:in `f': uninitialized constant Y (NameError) from bug.rb:23:in `
' or 1.9.3-head: $ ruby -v ruby 1.9.3p0 (2011-11-08) [x86_64-darwin10.8.0] $ ruby bug.rb X::Y bug.rb:18:in `f': uninitialized constant Y (NameError) from bug.rb:23:in `
' I discovered this because it RSpec specs when going to 1.9.3: https://github.com/rspec/rspec-core/issues/506 -- http://redmine.ruby-lang.org