Now that const_get supports "Foo::Bar" syntax, so should const_defined?.
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
object.c: nested path const_defined?
- object.c (rb_mod_const_defined): support nested class path as well as const_get. [Feature #7414]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44194 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
#3 [ruby-core:50550] Updated by sferik (Erik Michaels-Ober) over 5 years ago
I also noticed this inconsistency. It seems very odd to have different behavior for Module#const_get and Module#const_defined?. I hope it's possible to get this change into 2.0.0. It's been a while since I've written any C but I'd be happy to contribute failing specs if that would be helpful.
#4 [ruby-core:50952] Updated by benolee (Ben Holley) over 5 years ago
I have been working on a patch, but I have some questions about expected behavior.
In the case when the parent is missing, for example:
# Foo is missing Object.const_defined?("Foo::Bar")
should it return false? Or raise NameError for "Foo"? Or call Object.const_missing(:Foo)?
Second, in the case when the parent is not a Module or Class, for example:
Foo = Object.new Object.const_defined?("Foo::Bar")
should it return false? Or raise error "Foo is not a class/module"?
#8 Updated by nobu (Nobuyoshi Nakada) over 4 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100