About Ruby Kernel Module

The reason I decided to put it together

I usually use puts and print, but I wondered who this is, so when I looked it up, it seems to be a method included in the kernel module. Since it became "Kernel module?", I checked it.

Kernel module

A module that defines methods that can be referenced by all classes. The Object class includes this module. The methods of the Object class are actually defined in this module. This is to accommodate method redefinition at the top level.

First, there are all superclasses called Object classes, and the methods defined here can be used for all objects. And since the Karnel module is included in this Object class, the result is that the method can be used anywhere. (By the way, a module is a function that cannot be instantiated like a class, but can define constants and methods.)

Like this.

talk.rb


#This part is the top level(Outside a class or module)
def say
  puts "hello"
end
#This part is the top level

#Since the Human class inherits the Object of the parent class, the say method can be used.
class Human
  def talk
    say
  end
end

human = Human.new()
human.talk
#=>hello

Finally

I did my own research, but I would appreciate it if you could point out any mistakes.

References

Object-oriented scripting language Ruby reference manual https://docs.ruby-lang.org/ja/latest/class/Kernel.html

Top level in Ruby https://www.javadrive.jp/ruby/method/index1.html

What is Ruby's top-level method after all? https://qiita.com/pink_bangbi/items/c08ec7b32fc6dd20baad

Recommended Posts

About Ruby Kernel Module
About the Kernel module
[Ruby] Module
About Ruby symbols
About ruby ​​form
About Ruby Hashes
About Ruby arrays
About Ruby inheritance
About ruby block
About Ruby Hashes
About Ruby Symbols
About Ruby variables
About Ruby methods
About Ruby error messages
About Ruby exception handling
About Ruby Hashes (continued)
About eval in Ruby
[ruby] About here documents
About Ruby if statement
About Ruby instance methods
[Ruby] About instance generation
About the [ruby] operator
Thinking about logic Ruby
What is a Ruby module?
Explanation about Ruby Range object
[Ruby on Rails] about has_secure_password
About regular expressions in Ruby
About Ruby hashes and symbols
Ruby About various iterative processes
About Ruby and object model
About Ruby classes and instances
[Ruby] Get parent module (moved)
Explanation about Ruby String object
About the behavior of ruby Hash # ==
About Ruby single quotes and double quotes
About Ruby product operator (&) and sum operator (|)
[Super Introduction] About Symbols in Ruby
About =
About object-oriented inheritance and about yield Ruby
[Ruby] Review about nesting of each
Explanation about Array object of Ruby
[Ruby on Rails] About bundler (for beginners)
[Ruby on Rails] About Active Record callbacks