Re: How does the class name magic with Class.new?

John Carter <[email protected]> Mon, 10 Jun 2019 16:27:48 +1200
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAFD1m3HmpyA28azgrYoSaimqfwFXSSPw+C0Px72wAorHB=Ax8w@mail.gmail.com>
I tried digging about the ruby source code to spot where the magic
happen and/or find the documentation on const_set that says it's magic
and that magic can be relied on....

..no luck so far.

Any pointers as to exactly where that magic is implemented?

On Mon, Jun 10, 2019 at 4:03 PM Matthew Kerwin <[email protected]> wrote:
>
> Yeah, no, that's pretty much exactly how it works.
>
> On Mon, 10 Jun 2019 at 13:51, John Carter <[email protected]> wrote:
> >
> > This seems like deep magic... Any idea how it works?
> >
> > a = Class.new
> > => #<Class:0x0000558d34f68b48>
> > > a.name
> > => nil
> > > B= a
> > => B
> > > a.name
> > => "B"
> > > C= a
> > => B
> > > C.name
> > => "B"
> >
> > It seems as if whenever you create a Constant it checks to see to see
> > if it is an unnamed class and then names it....
> >
> > That seems..... too magic.
> >
> > --
> > John Carter
> > Phone : (64)(3) 358 6639
> > Tait Electronics
> > PO Box 1645 Christchurch
> > New Zealand
> >
> > --
> > This Communication is Confidential. We only send and receive email on the
> >
> > basis of the terms set out at www.taitradio.com/email_disclaimer
> > <http://www.taitradio.com/email_disclaimer>
> >
> > Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>
>
>
> --
>   Matthew Kerwin
>   https://matthew.kerwin.net.au/
>
> Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>



-- 
John Carter
Phone : (64)(3) 358 6639
Tait Electronics
PO Box 1645 Christchurch
New Zealand

-- 
This Communication is Confidential. We only send and receive email on the

basis of the terms set out at www.taitradio.com/email_disclaimer 
<http://www.taitradio.com/email_disclaimer>

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>