Kernel Methods in Ruby

来源:互联网 发布:淘宝爱泉机油假货 编辑:程序博客网 时间:2024/05/19 19:12

Kernel is a special class(actually, a module) whose methods are made avaiable in every class and through the scope of ruby.

Consider the puts method you mostly use:

puts "Programming is an artist!"

However, unlike the methods on your own classes. puts isn't prefixed by the name of the class or object upon which to complete the method.

It would seem logical that the full command sholud be written like screen.put or display.puts, as puts display text on the screen.However, the puts is a method made available from Kernel module---a special type of class packed full of standard, commonly used methods,making your code easier to read and write.

原创粉丝点击