methods
,instance_methods
,public_methods
, private_methods
and protected_methods
所有人都接受一个血清参数,以确定贵国的物体父母的方法是否包含在内。
例如:
ruby-1.9.2-p0 > class MyClass < Object; def my_method; return true; end; end;
ruby-1.9.2-p0 > MyClass.new.public_methods
=> [:my_method, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :__id__, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__]
ruby-1.9.2-p0 > MyClass.new.public_methods(false)
=> [:my_method]
如@Marnen所指出的,这些方法在动态上作了界定(例如>method_missing
)。 你对这些图书馆的唯一旁观是,希望你重新使用的图书馆有充分记录。