Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

constantize now less robust in 2.3.3

#2975

Constantize cannot access internal classes declared in super classes in 2.3.3 but seems to be working fine in 2.1.0

class A
 class B
 end 
end

class C < A
end

In 2.3.3 console:

C::B => A::B

'C::B'.constantize NameError: uninitialized constant C::B

from /Users/tim/src/property/rails23/vendor/rails/activesupport/lib/active_support/dependencies.rb:105:in `const_missing'
from /Users/tim/src/property/rails23/vendor/rails/activesupport/lib/active_support/inflector.rb:361:in `constantize'
from /Users/tim/src/property/rails23/vendor/rails/activesupport/lib/active_support/inflector.rb:360:in `each'
from /Users/tim/src/property/rails23/vendor/rails/activesupport/lib/active_support/inflector.rb:360:in `constantize'
from /Users/tim/src/property/rails23/vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
from (irb):4

But it works fine in 2.1.0:

'C::B'.constantize => A::B

Reported by Rajesh · July 30th, 2009 @ 07:50 PM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.3, constantize to 2.3.3, bugmash, constantize

    August 7th, 2009 @ 02:39 PM

  2. Ryan Bigg
    Ryan Bigg

    Here's a patch that proves that it is broken.

    August 8th, 2009 @ 01:26 AM

  3. Michael Koziarski
    Michael Koziarski
    • State changed from new to wontfix

    This appears to be 'just how it is' with ruby unfortunately:

    >> Gamma.const_get("Beta")
    => Alpha::Beta
    >> Gamma.const_defined?("Beta")
    => false
    

    We check const_defined? before calling const_get and ruby returns false here. This is a ruby bug / feature and should probably be fixed upstream.

    If you get a work around from upstream, we'd be happy to use it here.

    August 8th, 2009 @ 03:06 AM

  4. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.3, bugmash, constantize to 2.3.3, constantize

    August 8th, 2009 @ 11:08 PM

  5. Akira Matsuda
    Akira Matsuda

    @nzkoz

    Indeed, it's already fixed in Ruby 1.9

    % cat const_defined.rb
    class Alpha
      class Beta; end
    end
    
    class Gamma < Alpha
    end
    
    puts Gamma::const_get('Alpha')
    
    puts Gamma::const_defined?('Alpha')
    
    % ruby18 const_defined.rb
    Alpha
    false
    
    % ruby19 const_defined.rb
    Alpha
    true
    

    I'm gonna ask Ruby 1.8.x maintainers whether this could be backported to 1.8 on not.

    August 8th, 2009 @ 11:52 PM

  6. Michael Koziarski