From: Tobias Cohen Date: 2009-11-19T08:38:01+09:00 Subject: Re: Inheriting from Object On 19/11/2009, at 10:16 AM, Mike Stephens wrote: > "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)". It looks like these methods are defined as /private/ methods of Object, so you can't call them from outside of the object. For some reason, irb confusingly makes public methods instead, so I had to write a test program to find this out. > 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? You are in the envelope of the "main" class, but Ruby has a special case for methods defined here - this thread is fairly informative: http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/7bb7b451a8f3cca7/98c4c62127b9d945 Tobias Cohen http://tobiascohen.com/