From: pharrington Date: 2009-11-19T08:50:09+09:00 Subject: Re: Inheriting from Object On Nov 18, 6:43 pm, pharrington wrote: > On Nov 18, 6:16 pm, Mike Stephens wrote: > > > > > > > I'm just working through Ruby Visual Quickstart Guide by Larry Ullman, > > which is quite an enjoyable book (so far). In it he has this : > > > "Methods defined outside of any class ... are automatically defined as > > part of the Object class. Because every class automatically inherits > > from the Object class, these methods are therefore inherited by every > > class." > > > When I tried this, it didn't work (ie write some methods and then > > declare a class and try and use those methods on new members of that > > class) . Ruby issues an error message - "private error > > called...(nomethoderror)". > > > I lodged a question on Larry's web site, and to his credit he replied in > > due course. He said "I'm sorry: what I wrote probably isn't clear there. > > Every object inherits the methods in the original Object, but they don't > > inherit methods created in situations like this. Sorry for the > > confusion!" > > > It raises an interesting question. When you write methods outside of a > > specific class block, you are in the envelope of some top level class, > > so why aren't these methods added? > > -- > > Posted viahttp://www.ruby-forum.com/. > > xeno@Clover:~/projects$ ruby -e "puts class << self; self; > end.inspect" > #> > > This says to me that top level is instance of class Object (which > mixes in Kernel), so methods defined in top level will be added to > that object's singleton class, not the base Object class. However this > is just a guess inspired by your question; I await the actual answer > to this. Ignore all this: I don't understand Ruby.