I'll start with a question: what would self
be inside a typical Kernel
method such as puts
? The closest thing to a meaningful self
inside puts
would probably be the Ruby runtime itself. Similarly for other "methods that really want to be functions" like Array
or fork
. So you can look at Kernel
as a dumping ground for methods that are, more or less, commands or messages to Ruby itself.
Kernel
also has odd methods like sub
and chop
that are really only useful for one-off ruby -e
scripts. These things tend to use $_
as an implied self
but I think they can be considered as special cases of the "commands to the Ruby runtime" as above.
Where does a method go when you want to be able to call that method on any object? I'd say that it would go into Object
. If the method is really a function in disguise and has no meaningful self
, then it would go into Kernel
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…