while going through Ruby, i encountered that BasicObject is the top most superclass of Class. When I tried
BasicObject.methods
, i get list of these 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__, :!=]
(I have Jruby present as well so some extra methods)
But when I call BasicObject.methods(false)
(false parameter for displaying methods of the same class itself), I get
=> [:method_missing, :singleton_method_added, :singleton_method_undefined, :singleton_method_removed]
I have a query, ideally class.methods with false param should return only its methods and BasicObject.superclass returns nil. Is there any other hierarchy? from where does these methods coming from.
I'm learning Ruby Apologozies if i'm missing something. Thanks
You are not asking what instance methods are defined on BasicObject
, that would be BasicObject.instance_methods
. You are asking, what methods you can call on BasicObject
. Well, BasicObject
is an object just like any other object, so you can call any method on it that is defined in its class (which in this case is Class
) or in the superclasses of its class (which in this case are Module
, Object
, Kernel
, and BasicObject
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With