Re: How does the class name magic with Class.new?
Matthew Kerwin <[email protected]> Mon, 10 Jun 2019 16:17:10 +1000
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CACweHNB-SU7ioD4qBE+3y+tpWCmxp0xTHLZts0MOLTY+e2aNYw@mail.gmail.com> |
In variable.c, check rb_const_set It's definitely a spec. On Mon, 10 Jun 2019 at 14:29, John Carter <[email protected]> wrote: > > 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> -- Matthew Kerwin https://matthew.kerwin.net.au/ Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>