Yehuda Katz
(ph) 718.877.1325


2011/11/30 Yukihiro Matsumoto <matz / ruby-lang.org>

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