On 21 January 2012 21:06, John Merlino <stoici...@aol.com> wrote:
> Then why:
>
> n = m.new
>
> doesnt "new" create an object that gives n access to m's class
> methods, as it did in the other case?
>
> On Jan 21, 3:03 pm, John Merlino <stoici...@aol.com> wrote:
>> This fails:
>> 1.9.2p290 :007 > B.new
>> NoMethodError: undefined method `new' for #<Object:0x007ff597d27820>
>>
>> When we instantiate B, the instance gets B's instance methods. But why
>> doesn't it get Class's instance method (new)?
>>
>> B inherits from Object which inherits from Class. It should have
>> looked up scope chain until it reached Class, since Object is an
>> instance of Class and therefore inherits from it.

You're getting "Class" and "class", and "Object" and "object" confused.
".new" is a class method of Class, not an instance method of Class. So
when you instanciate an object, you can't call ".new" on it. Although
you could call "B.class.new".

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to