Aas*_*ish 5 ruby methods jruby
在学习 Ruby 时,我发现 BasicObject 是 Class 的最顶级超类。当我尝试时
BasicObject.methods,我得到了这些方法的列表
[:method_missing, :singleton_method_added, :singleton_method_undefined, :singleton_method_removed, :new, :become_java!, :allocate, :superclass, :java_class, :class_variables, :<=, :public_instance_methods, :prepend, :class_variable_get, :public_constant, :singleton_class?, :instance_methods, :freeze, :instance_method, :const_defined?, :to_s, :constants, :ancestors, :private_instance_methods, :===, :included_modules, :==, :using, :class_eval, :const_get, :refine, :protected_instance_methods, :public_instance_method, :class_variable_defined?, :inspect, :name, :private_constant, :<, :hash, :>, :>=, :module_exec, :protected_method_defined?, :module_eval, :const_missing, :class_exec, :const_set, :private_method_defined?, :public_class_method, :autoload, :<=>, :include, :public_method_defined?, :autoload?, :class_variable_set, :include?, :remove_class_variable, :deprecate_constant, :private_class_method, :method_defined?, :include_class, :handle_different_imports, :java_kind_of?, :public_send, :frozen?, :protected_methods, :java_implements, :public_method, :java, :singleton_methods, :untaint, :javafx, :enum_for, :private_methods, :method, :instance_variables, :object_id, :extend, :itself, :instance_variable_set, :respond_to?, :java_name, :methods, :to_java, :java_package, :singleton_class, :public_methods, :to_enum, :display, :tainted?, :instance_variable_defined?, :untrusted?, :define_singleton_method, :!~, :nil?, :com, :instance_of?, :java_require, :javax, :java_signature, :tap, :java_annotation, :send, :trust, :instance_variable_get, :is_a?, :eql?, :java_field, :remove_instance_variable, :untrust, :class, :=~, :org, :taint, :kind_of?, :clone, :dup, :!, :equal?, :instance_exec, :__id__, :instance_eval, :__send__, :!=]
Run Code Online (Sandbox Code Playgroud)
(我也有 Jruby,所以有一些额外的方法)
但是当我调用BasicObject.methods(false)(用于显示同一类本身的方法的假参数)时,我得到
=> [:method_missing, :singleton_method_added, :singleton_method_undefined, :singleton_method_removed]
Run Code Online (Sandbox Code Playgroud)
我有一个查询,理想情况下,带有 false 参数的 class.methods 应该只返回它的方法,而 BasicObject.superclass 返回 nil。有没有其他层次?这些方法来自哪里。
如果我遗漏了什么,我正在学习 Ruby Apologozies。谢谢