ruby的 Class,Module,Object,Kernel
打开irb:
puts ‘abc’.class ==> String
puts String.class ==> Class
puts Class.class ==> Class
以上说明 所有的字符串都是 String类的实例,而 String类 是 Class类的实例
Class.superclass ==> Module
Module.superclass ==> Object
Object.superclass ==> nil
以上说明: Class类继承了Module类,Module类继承了Object类,Object类是所有类的祖先
Class.class ==> class
Module.class ==> class
Object.class ==> class
Kernel.class ==> Module
以上说明:由于Class, Module, Object 都是class,而Kernel是Module
Class.ancdstors ==> [Class,Module,Object,Kernel]
Module.ancestors ==> [Module,Object,Kernel]
Object.ancestors ==> [Object,Kernel]
Kernel.ancestors ==> [Kernel]
以上说明:
因为Object混入了Kernel这个模块,又由于Object是Ruby中所有类的父类,这样以来,Kernel中内建的核心函数就可以被Ruby中所有的类和对象访问。
Object的实例方法由Kernel模块定义。
Kernel模块中定义了private method和public method
对于一个普通的对象,可以直接调用Kernel的public method
在irb中运行: a=Object.new
输出:=> #
运行: a.public_methods
=> ["inspect", "clone", "public_methods", "display", "instance_variable_defined?", "equal?", "freeze", "methods", "respond_to?", "dup", "to_yaml_style",
"instance_variables", "__id__", "method", "eql?", "id", "singleton_methods", "send", "taint", "to_yaml_properties", "frozen?", "instance_variable_get", "__send__", "instance_of?", "to_a", "to_yaml", "type", "protected_methods", "instance_eval", "object_id", "require_gem", "==", "require", "===", "taguri", "instance_variable_set", "kind_of?", "extend", "gem", "to_s", "taguri=", "hash", "class", "private_methods", "=~", "tainted?", "untaint", "nil?", "is_a?"]
https://www.cnblogs.com/cnblogsfans/archive/2009/01/27/1381134.html