Forum: Ruby-core [ruby-trunk - Feature #7414][Open] Now that const_get supports "Foo::Bar" syntax, so should const_de

Posted by Robert Gleeson (robgleeson)
on 2012-11-20 17:09
(Received via mailing list)
Issue #7414 has been reported by robertgleeson (Robert Gleeson).

----------------------------------------
Feature #7414: Now that const_get supports "Foo::Bar" syntax, so should 
const_defined?.
https://bugs.ruby-lang.org/issues/7414

Author: robertgleeson (Robert Gleeson)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0.0


class Foo
end
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
Posted by Robert Gleeson (robgleeson)
on 2012-11-20 19:17
(Received via mailing list)
Issue #7414 has been updated by robertgleeson (Robert Gleeson).


I realise defined? with a constant works just as well but this is about 
API constancy.
I'd expect const_get & const_defined? to support the same query language 
("Object::Foo").
----------------------------------------
Feature #7414: Now that const_get supports "Foo::Bar" syntax, so should 
const_defined?.
https://bugs.ruby-lang.org/issues/7414#change-33356

Author: robertgleeson (Robert Gleeson)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0.0


class Foo
end
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
Posted by Robert Gleeson (robgleeson)
on 2012-11-21 15:56
(Received via mailing list)
Issue #7414 has been updated by robertgleeson (Robert Gleeson).


robertgleeson (Robert Gleeson) wrote:
> I realise defined? with a constant works just as well but this is about API 
consistency.
> I'd expect const_get & const_defined? to support the same syntax 
("Object::Foo").


----------------------------------------
Feature #7414: Now that const_get supports "Foo::Bar" syntax, so should 
const_defined?.
https://bugs.ruby-lang.org/issues/7414#change-33399

Author: robertgleeson (Robert Gleeson)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0.0


class Foo
end
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
Posted by mame (Yusuke Endoh) (Guest)
on 2012-11-24 03:49
(Received via mailing list)
Issue #7414 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to tenderlovemaking (Aaron Patterson)

Aaron, can you fix it easily?

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #7414: Now that const_get supports "Foo::Bar" syntax, so should 
const_defined?.
https://bugs.ruby-lang.org/issues/7414#change-33750

Author: robertgleeson (Robert Gleeson)
Status: Assigned
Priority: Normal
Assignee: tenderlovemaking (Aaron Patterson)
Category:
Target version: 2.0.0


class Foo
end
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
Posted by sferik (Erik Michaels-Ober) (Guest)
on 2012-12-04 08:37
(Received via mailing list)
Issue #7414 has been updated by sferik (Erik Michaels-Ober).


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.
----------------------------------------
Feature #7414: Now that const_get supports "Foo::Bar" syntax, so should 
const_defined?.
https://bugs.ruby-lang.org/issues/7414#change-34392

Author: robertgleeson (Robert Gleeson)
Status: Assigned
Priority: Normal
Assignee: tenderlovemaking (Aaron Patterson)
Category:
Target version: 2.0.0


class Foo
end
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
Posted by benolee (Ben Holley) (Guest)
on 2012-12-17 20:36
(Received via mailing list)
Issue #7414 has been updated by benolee (Ben Holley).


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"?

----------------------------------------
Feature #7414: Now that const_get supports "Foo::Bar" syntax, so should 
const_defined?.
https://bugs.ruby-lang.org/issues/7414#change-34808

Author: robertgleeson (Robert Gleeson)
Status: Assigned
Priority: Normal
Assignee: tenderlovemaking (Aaron Patterson)
Category:
Target version: 2.0.0


class Foo
end
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
Posted by Nobuyoshi Nakada (nobu)
on 2013-01-08 18:31
(Received via mailing list)
Issue #7414 has been updated by nobu (Nobuyoshi Nakada).


I vote for false in both cases, like defined? operator.
----------------------------------------
Feature #7414: Now that const_get supports "Foo::Bar" syntax, so should 
const_defined?.
https://bugs.ruby-lang.org/issues/7414#change-35288

Author: robertgleeson (Robert Gleeson)
Status: Assigned
Priority: Normal
Assignee: tenderlovemaking (Aaron Patterson)
Category:
Target version: 2.0.0


class Foo
end
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
Posted by ko1 (Koichi Sasada) (Guest)
on 2013-02-24 13:25
(Received via mailing list)
Issue #7414 has been updated by ko1 (Koichi Sasada).


aaron, could you continue this discussion?

----------------------------------------
Feature #7414: Now that const_get supports "Foo::Bar" syntax, so should 
const_defined?.
https://bugs.ruby-lang.org/issues/7414#change-36911

Author: robertgleeson (Robert Gleeson)
Status: Assigned
Priority: Normal
Assignee: tenderlovemaking (Aaron Patterson)
Category:
Target version: 2.0.0


class Foo
end
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
Posted by ko1 (Koichi Sasada) (Guest)
on 2013-02-24 13:25
(Received via mailing list)
Issue #7414 has been updated by ko1 (Koichi Sasada).

Target version changed from 2.0.0 to 2.1.0


----------------------------------------
Feature #7414: Now that const_get supports "Foo::Bar" syntax, so should 
const_defined?.
https://bugs.ruby-lang.org/issues/7414#change-36912

Author: robertgleeson (Robert Gleeson)
Status: Assigned
Priority: Normal
Assignee: tenderlovemaking (Aaron Patterson)
Category:
Target version: 2.1.0


class Foo
end
Object.const_get "Object::Foo" => Foo
Object.const_defined? "Object::Foo" => NameError (expected true).
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.