Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of `Kernel`?

Tags:

oop

ruby

  1. What is the purpose of the Kernel module? What would change if all the things currently defined on Kernel were defined on Object, and there were no such module as Kernel?
  2. When I want to define a method that can be called on any object, should I define that on Kernel or on Object?
like image 362
sawa Avatar asked Apr 08 '14 02:04

sawa


People also ask

What is the main purpose of a kernel?

It is the core that provides basic services for all other parts of the OS. It is the main layer between the OS and underlying computer hardware, and it helps with tasks such as process and memory management, file systems, device control and networking.

What is kernel in operating system and what are the purposes of this kernel system?

Definition. The kernel is the most important part of the operating system. It is the primary interface between the hardware and the processes of a computer. The kernel connects these two in order to adjust resources as effectively as possible.

What is a kernel and what is its role?

The kernel is a computer program at the core of a computer's operating system and generally has complete control over everything in the system. It is the portion of the operating system code that is always resident in memory and facilitates interactions between hardware and software components.


1 Answers

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.

like image 83
mu is too short Avatar answered Oct 16 '22 18:10

mu is too short