From d35f8ea8858ab34733f35d3e0abf4f7a8fed54c9 Mon Sep 17 00:00:00 2001 From: mame Date: Thu, 17 Jun 2010 16:58:25 +0000 Subject: * object.c: Object#public_methods, private_methods, etc. returns method ids that belong to the class or the singleton class(es) of the object. [ruby-dev:41613] * class.c: on the other hand, Module#public_instance_methods, etc. returns method ids that belong to the module itself (even if the module is singleton, it does not return method ids of super class(es); see [ruby-core:28837]). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 107 +++------------------------------------------------------------ 1 file changed, 4 insertions(+), 103 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 414c3a9159..f52522db90 100644 --- a/object.c +++ b/object.c @@ -1751,109 +1751,10 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod) return RTEST(recur) ? rb_const_defined(mod, id) : rb_const_defined_at(mod, id); } -/* - * call-seq: - * obj.methods -> array - * - * Returns a list of the names of methods publicly accessible in - * obj. This will include all the methods accessible in - * obj's ancestors. - * - * class Klass - * def kMethod() - * end - * end - * k = Klass.new - * k.methods[0..9] #=> [:kMethod, :freeze, :nil?, :is_a?, - * # :class, :instance_variable_set, - * # :methods, :extend, :__send__, :instance_eval] - * k.methods.length #=> 42 - */ - -static VALUE -rb_obj_methods(int argc, VALUE *argv, VALUE obj) -{ - retry: - if (argc == 0) { - VALUE args[1]; - - args[0] = Qtrue; - return rb_class_instance_methods(1, args, CLASS_OF(obj)); - } - else { - VALUE recur; - - rb_scan_args(argc, argv, "1", &recur); - if (RTEST(recur)) { - argc = 0; - goto retry; - } - return rb_obj_singleton_methods(argc, argv, obj); - } -} - -/* - * call-seq: - * obj.protected_methods(all=true) -> array - * - * Returns the list of protected methods accessible to obj. If - * the all parameter is set to false, only those methods - * in the receiver will be listed. - */ - -static VALUE -rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj) -{ - if (argc == 0) { /* hack to stop warning */ - VALUE args[1]; - - args[0] = Qtrue; - return rb_class_protected_instance_methods(1, args, CLASS_OF(obj)); - } - return rb_class_protected_instance_methods(argc, argv, CLASS_OF(obj)); -} - -/* - * call-seq: - * obj.private_methods(all=true) -> array - * - * Returns the list of private methods accessible to obj. If - * the all parameter is set to false, only those methods - * in the receiver will be listed. - */ - -static VALUE -rb_obj_private_methods(int argc, VALUE *argv, VALUE obj) -{ - if (argc == 0) { /* hack to stop warning */ - VALUE args[1]; - - args[0] = Qtrue; - return rb_class_private_instance_methods(1, args, CLASS_OF(obj)); - } - return rb_class_private_instance_methods(argc, argv, CLASS_OF(obj)); -} - -/* - * call-seq: - * obj.public_methods(all=true) -> array - * - * Returns the list of public methods accessible to obj. If - * the all parameter is set to false, only those methods - * in the receiver will be listed. - */ - -static VALUE -rb_obj_public_methods(int argc, VALUE *argv, VALUE obj) -{ - if (argc == 0) { /* hack to stop warning */ - VALUE args[1]; - - args[0] = Qtrue; - return rb_class_public_instance_methods(1, args, CLASS_OF(obj)); - } - return rb_class_public_instance_methods(argc, argv, CLASS_OF(obj)); -} +VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj); +VALUE rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj); +VALUE rb_obj_private_methods(int argc, VALUE *argv, VALUE obj); +VALUE rb_obj_public_methods(int argc, VALUE *argv, VALUE obj); /* * call-seq: -- cgit v1.2.3