liveBook · Manning

Kernel

As explained in The Well-Grounded Rubyist, Fourth Edition

Kernel is Ruby's built-in module containing fundamental methods that are available to Object instances through inclusion in Object.

Kernel is Ruby’s built-in module for many fundamental methods shared by ordinary objects. Object mixes in Kernel, so instances of Object and its descendants can use Kernel’s instance methods. section 4.0 section 4.2.1

A bareword call

puts "Hello" The call has no explicit receiver because puts is a private instance method of Kernel. Object’s inclusion of Kernel makes this style available at the top level and to ordinary objects. section 5.4.2

Kernel supplies methods used in both short scripts and larger programs:

  • puts and print for output. section 5.4.2
  • require and load for bringing code into a program. section 5.4.2
  • raise for raising exceptions, along with methods for reading, writing, running system commands, and exiting programs. section 5.4.2
  • Private methods defined at the top level also become Kernel methods, making them available as bareword calls. section 5.5
$ ruby -e 'p Kernel.private_instance_methods.sort'

Inspect Kernel’s private instance methods with Ruby’s private_instance_methods method and sort the resulting names. section 5.4.2

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains Kernel’s place in method lookup, its inclusion in Object, and its private methods without detailing interpreter implementations.
Examples
Uses bareword puts and print calls, top-level methods, and private_instance_methods inspection.
What it assumes
Assumes familiarity with classes, inheritance, objects, and method calls while clarifying Kernel’s relationship to Object.
What you can do after
Evaluate/understand why common bareword calls work and inspect the private methods supplied by Kernel.
How it connects
Connects Kernel with Object, BasicObject, modules, inheritance, method lookup, private methods, and the default receiver.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.