From: Aaron Patterson Date: 2011-12-01T10:04:00+09:00 Subject: [ruby-core:41419] Re: [ruby-trunk - Bug #5690][Open] Module#qualified_const_get --Q68bSM7Ycu6FN28Q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Nov 30, 2011 at 04:52:36PM +0900, Yehuda Katz wrote: > On Tue, Nov 29, 2011 at 10:04 PM, Yukihiro Matsumoto = wrote: >=20 > > Hi, > > > > In message "Re: [ruby-core:41404] [ruby-trunk - Bug #5690][Open] > > Module#qualified_const_get" > > on Wed, 30 Nov 2011 12:10:02 +0900, Yehuda Katz > > writes: > > > > |It would be great if there was a way to dynamically load a constant pa= th: > > | > > | module Foo > > | module Bar > > | module Baz > > | end > > | end > > | end > > | > > | Foo.qualified_const_get("Bar::Baz") =3D> Foo::Bar::Baz > > > > Interesting. > > > > * is there any use-case for this method? > > >=20 > We use it often in Rails. When serializing objects to yaml, the fully qualified class name is=20 emitted. When reviving those objects, the class name comes back as a=20 string, so psych uses rb_path2class to find the constant. > > * if Bar is not a class nor module, what kind error should be raised? > > >=20 > TypeError: "(=E2=80=A6) is not a class/module" Agreed. > > * is qualified_const_get an appropriate name for the function? > Unknown. It's what we call it in Rails ;) Yes. --=20 Aaron Patterson http://tenderlovemaking.com/ --Q68bSM7Ycu6FN28Q Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iQEcBAEBAgAGBQJO1tJqAAoJEJUxcLy0/6/GcUIIAIR6YD0+B54nAAluuNOsvI4v 7T9t2InExT5kfhV0tIo7FgCXzfZ9mcFnLEnOq/RM6jjvCzeycuwPnmIgne/iCy7G DcyafEXkjerjZBUng531LwERHYg6hb2+WC5+HR0RGsQ5toTN8QymxDS5pp34jeS+ X9/Lz3VulxeLy0aDL9H3XvjSdOGiAi4oL6gJ0UOHwK6BrLcKNRhII0Hjr45dG0jw qstNGni93AUfY6Jkp5MRm1litWVDC1bnQqFDewYqJ/c4Z/N7C51sO4dQj6rW6Onk 7RkgCSRRszIF+4wgeh/MlGd31ACZ5pKUIzDxVrRJFzGl09NM3twjcL2XGAwVN8Y= =+iPv -----END PGP SIGNATURE----- --Q68bSM7Ycu6FN28Q--