From: Yehuda Katz Date: 2011-12-01T05:59:21+09:00 Subject: [ruby-core:41416] Re: [ruby-trunk - Bug #5690][Open] Module#qualified_const_get --0016364eef7a80118a04b2fa0216 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Yehuda Katz (ph) 718.877.1325 2011/11/30 Yukihiro Matsumoto > Hi, > > In message "Re: [ruby-core:41408] Re: [ruby-trunk - Bug #5690][Open] > Module#qualified_const_get" > on Wed, 30 Nov 2011 16:52:36 +0900, Yehuda Katz > writes: > > |> * is there any use-case for this method? > | > |We use it often in Rails. > > Could you show us the concrete example? It is difficult for me to > imagine. > One case is to convert path names (file system paths) into constants. In general, Rails uses inflections to convert names from different contexts. In the router, for instance, "foo/bar" is used to represent namespaces, which are then converted into "Foo::Bar" and then Foo::Bar. > > |> * if Bar is not a class nor module, what kind error should be raised? > |> > | > |TypeError: "(=85) is not a class/module" > > Understood. > > |> * is qualified_const_get an appropriate name for the function? > |> > | > |Unknown. It's what we call it in Rails ;) > > How about > > Foo.const_get("Bar::Baz") > Sounds good to me. Currently, trying to const_set or const_get a name with :: in it produces a NameError, so it should not introduces new issues. > > or > > Foo.const_get(:Bar, :Baz) > This doesn't satisfy the use-case in question. > > ? > > matz. > > --0016364eef7a80118a04b2fa0216 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
Yehuda Katz
(ph) 718.877.1325


2011/11/30 Yukihiro Matsumoto <matz@ruby-lang.org&g= t;
Hi,

In message "Re: [ruby-core:41408] Re: [ruby-trunk - Bug #5690][Open] M= odule#qualified_const_get"
=A0 =A0on Wed, 30 Nov 2011 16:52:36 +0900, Yehuda Katz &= lt;wycats@gmail.com> writes:

|> * is there any use-case for this method?
|
|We use it often in Rails.

Could you show us the concrete example? =A0It is difficult for me to<= br> imagine.

One case is to convert path na= mes (file system paths) into constants.

In general= , Rails uses inflections to convert names from different contexts. In the r= outer, for instance, "foo/bar" is used to represent namespaces, w= hich are then converted into "Foo::Bar" and then Foo::Bar.
=A0

|> * if Bar is not a class nor module, what kind error should be raised?=
|>
|
|TypeError: "(=85) is not a class/module"

Understood.

|> * is qualified_const_get an appropriate name for the function?
|>
|
|Unknown. It's what we call it in Rails ;)

How about

=A0Foo.const_get("Bar::Baz")

Sounds good to me. Currently, trying to const_set or const_get a name with= :: in it produces a NameError, so it should not introduces new issues.
=A0

or

=A0Foo.const_get(:Bar, :Baz)

This does= n't satisfy the use-case in question.
=A0

?

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0matz.


--0016364eef7a80118a04b2fa0216--