On Thu, Mar 14, 2013 at 2:42 PM, Kedar Mhaswade <[email protected]> wrote:
>>>> 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"?

Yes, see above. It's at least imprecise since "abc" does not reference
a single instance of String but it will produce a new instance every
time it is executed.  See the part of my previous mail you did not
quote.

>>> 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?

I don't know.  But I do know that this is an implementation detail of
MRI which is invisible to the user of the language.  Other than
singleton classes these new class objects cannot in any way be
observed by Ruby programs:

irb(main):001:0> a = Object.superclass.object_id
=> -1073527798
irb(main):002:0> module X end
=> nil
irb(main):003:0> class Object
irb(main):004:1> include X
irb(main):005:1> end
=> Object
irb(main):006:0> b = Object.superclass.object_id
=> -1073527798
irb(main):007:0> a == b
=> true

The information may be right or outdated but it does not necessarily
help users of the language to understand how Ruby works.

Cheers

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- 
[email protected] | 
https://groups.google.com/d/forum/ruby-talk-google?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to