From: Gary Wright Date: 2009-12-31T08:00:19+09:00 Subject: Re: Object.send(:remove_const, :Polygon) --Apple-Mail-1-438974456 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Dec 30, 2009, at 5:47 PM, Ralph Shnelvar wrote: > Consider >=20 >=20 > irb(main):001:0> class X > irb(main):002:1> end > =3D> nil > irb(main):003:0> > irb(main):004:0* class Y < X > irb(main):005:1> end > =3D> nil > irb(main):006:0> > irb(main):007:0* Object.send(:remove_const, :X) > =3D> X > irb(main):008:0> > irb(main):009:0* X.class > NameError: uninitialized constant X > from (irb):9 > from :0 > irb(main):010:0> Y.class > =3D> Class > irb(main):011:0> Y.superclass > =3D> X > irb(main):012:0> Y.superclass.superclass > =3D> Object > irb(main):013:0> >=20 >=20 > How can the class X still exist when it has been removed????? remove_const doesn't destroy the class object it just deletes the = binding represented by the constant. Ruby arranges for a class to have a name (a string label) that matches = the first constant that the class is bound to. The name still remains = even if the constant binding is removed (via remove_const). ?> a =3D Class.new =3D> # >> a.name =3D> "" >> Foobar =3D a =3D> Foobar >> a.name =3D> "Foobar" >> Object.send(:remove_const, :Foobar) =3D> Foobar >> Foobar NameError: uninitialized constant Foobar from (irb):31 >> a.name =3D> "Foobar" >> a.inspect =3D> "Foobar" --Apple-Mail-1-438974456--