This project is archived and is in readonly mode.
constantize now less robust in 2.3.3
Reported by Rajesh | July 30th, 2009 @ 07:50 PM
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
Comments and changes to this ticket
-
CancelProfileIsBroken August 7th, 2009 @ 02:39 PM
- Tag changed from 2.3.3, constantize to 2.3.3, bugmash, constantize
-
Michael Koziarski August 8th, 2009 @ 03:06 AM
- 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.
-
CancelProfileIsBroken August 8th, 2009 @ 11:08 PM
- Tag changed from 2.3.3, bugmash, constantize to 2.3.3, constantize
-
Akira Matsuda August 8th, 2009 @ 11:52 PM
@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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>