From: Kedar Mhaswade Date: 2013-03-14T22:42:30+09:00 Subject: Re: Understanding Ruby Classes, Objects and Methods. >>> abc is an instance of String >>> This is not true. Said expression is a constructor of a String which >>> will return a different String instance on every evaluation. >> >> I don't find that statement in the doc. I only have: >> >> 2. "abc" is an instance of String. > > Yes, that's it. > And do you suggest that that statement is "not true"? >> and I believe that is correct because String is the class of all strings >> in Ruby. > > The fact that Fixnums are immediate values is _completely_ irrelevant > for how they are used. Perhaps. All I wanted to say was is reference to the phrase "is a". That's when I introduced variables and I thought the difference in intermediate values and references should be clarified at that point. Since then, I have clarified the text even further. > >> book) to what I wrote. The topic is about including Modules in Classes. > I don't have the book handy. Maybe you can quote the relevant text. > >> Even if you say that the chain returned by ancestors is traversed, where >> is the reference for code for something like Mod#m? Since the same >> module Mod can be included in several classes, an instance of anonymous >> class for each including class seems right. But I agree, I don't yet >> know how this happens internally in the interpreter. > > So you say you do not know how it works but claim there is an > anonymous class - solely because it "seems right"? Why does it "seem > right"? I had though you wanted to convey facts. Yes. And I should really know what happens internally. But here is what Dave says in his book (on page 379 of the Programming Ruby PDF -- Version: 2010-11-15 that I purchased from Prag Prog): ---------------------------------------------------------------- To get around this, Ruby uses a clever trick. When you include a module in class Example, Ruby constructs a new class object, makes it the superclass of Example, and then sets the superclass of the new class to be the original superclass of Example. It then references the module from this new class object in such a way that when you look a method up in this class, it actually looks it up in the module, as shown in Figure 24.5, on the next page. ---------------------------------------------------------------- Is this not right? -- Posted via http://www.ruby-forum.com/.