From: Gavin Sinclair Date: 2003-09-12T10:54:52+09:00 Subject: Re: How are global methods defined? > On Thu, 11 Sep 2003 15:56:35 +0900 > "Gavin Sinclair" wrote: > >> > [Jason:] >> > >> > But anyway, the question is, what happens to methods defined at the >> top-level like that? Are they just added to Object? And if that's >> the case, why do we even have Kernel? >> >> Top-level methods become private methods of Object, so I'm told. That >> should make them invisible to subclasses. Ho hum. >> >> Anyway, we have Kernel so that lots of methods can be gathered >> together and made available (via inclusion in Object). > > But why not add just add private methods to Object if it has the same > effect? What's the point of having Kernel? It seems like going the long > way around. > > Jason Creighton Well, it doesn't cost anything, and it's a good separation of concerns. The stuff in Kernel doesn't conceptually belong in Object. Yes, it causes some pain and suffering when you can't find the documentation :) But every Rubyist learns about Kernel pretty soon. And it's worth it in the long run to avoid bloat and cognitive dissonance. If I could hand down only one piece of advice to a new Rubyist, it's this: get 'ri' (why oh why is this not in the distribution?) and read most of the things you can find in there. Then you know what is built in to Ruby and what it not, and you know where to find the most important things. Here is the end of the output from running 'ri': 'ri' has documentation for the classes and modules: Array, Bignum, Binding, Class, Comparable, Continuation, Dir, Enumerable, Errno, Exception, FalseClass, File, File::Stat, FileTest, Fixnum, Float, GC, Hash, IO, Integer, Kernel, Marshal, MatchData, Math, Method, Module, NilClass, Numeric, Object, ObjectSpace, Proc, Process, Process::Status, Range, Regexp, Signal, String, Struct, Struct::Tms, Symbol, Thread, ThreadGroup, Time, TrueClass, UnboundMethod All of these are worth knowing about in some detail. Cheers, Gavin