summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-29 14:48:05 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-29 14:48:05 +0000
commit55f779aaabb4942366067e7145c2ccc014872202 (patch)
treefa5bd46e81df78c2b0c916706114f9eff6020023
parentac8f4a4d38a82e3b8f574b1542dc71a9c6c84628 (diff)
merges r28357 from trunk into ruby_1_9_2.
-- * 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/branches/ruby_1_9_2@28480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--class.c97
-rw-r--r--object.c107
3 files changed, 107 insertions, 108 deletions
diff --git a/ChangeLog b/ChangeLog
index b4b6064e7b..738009e540 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Fri Jun 18 01:50:21 2010 Yusuke Endoh <mame@tsg.ne.jp>
+
+ * 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]).
+
Tue Jun 29 21:16:05 2010 Masaya Tarui <tarui@ruby-lnag.org>
* ext/stringio/stringio.c (strio_write): add RB_GC_GUARD.
diff --git a/class.c b/class.c
index a6871baeea..ac51f8e02b 100644
--- a/class.c
+++ b/class.c
@@ -833,7 +833,7 @@ method_entry(ID key, const rb_method_entry_t *me, st_table *list)
}
static VALUE
-class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, long, VALUE))
+class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func) (ID, long, VALUE))
{
VALUE ary;
int recur;
@@ -852,6 +852,7 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, lo
for (; mod; mod = RCLASS_SUPER(mod)) {
st_foreach(RCLASS_M_TBL(mod), method_entry, (st_data_t)list);
if (BUILTIN_TYPE(mod) == T_ICLASS) continue;
+ if (obj && FL_TEST(mod, FL_SINGLETON)) continue;
if (!recur) break;
}
ary = rb_ary_new();
@@ -891,7 +892,7 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, lo
VALUE
rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
{
- return class_instance_method_list(argc, argv, mod, ins_methods_i);
+ return class_instance_method_list(argc, argv, mod, 0, ins_methods_i);
}
/*
@@ -906,7 +907,7 @@ rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
VALUE
rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
{
- return class_instance_method_list(argc, argv, mod, ins_methods_prot_i);
+ return class_instance_method_list(argc, argv, mod, 0, ins_methods_prot_i);
}
/*
@@ -929,7 +930,7 @@ rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
VALUE
rb_class_private_instance_methods(int argc, VALUE *argv, VALUE mod)
{
- return class_instance_method_list(argc, argv, mod, ins_methods_priv_i);
+ return class_instance_method_list(argc, argv, mod, 0, ins_methods_priv_i);
}
/*
@@ -944,7 +945,93 @@ rb_class_private_instance_methods(int argc, VALUE *argv, VALUE mod)
VALUE
rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
{
- return class_instance_method_list(argc, argv, mod, ins_methods_pub_i);
+ return class_instance_method_list(argc, argv, mod, 0, ins_methods_pub_i);
+}
+
+/*
+ * call-seq:
+ * obj.methods -> array
+ *
+ * Returns a list of the names of methods publicly accessible in
+ * <i>obj</i>. This will include all the methods accessible in
+ * <i>obj</i>'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
+ */
+
+VALUE
+rb_obj_methods(int argc, VALUE *argv, VALUE obj)
+{
+ retry:
+ if (argc == 0) {
+ VALUE args[1];
+
+ args[0] = Qtrue;
+ return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_i);
+ }
+ 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 <i>obj</i>. If
+ * the <i>all</i> parameter is set to <code>false</code>, only those methods
+ * in the receiver will be listed.
+ */
+
+VALUE
+rb_obj_protected_methods(int argc, VALUE *argv, VALUE obj)
+{
+ return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_prot_i);
+}
+
+/*
+ * call-seq:
+ * obj.private_methods(all=true) -> array
+ *
+ * Returns the list of private methods accessible to <i>obj</i>. If
+ * the <i>all</i> parameter is set to <code>false</code>, only those methods
+ * in the receiver will be listed.
+ */
+
+VALUE
+rb_obj_private_methods(int argc, VALUE *argv, VALUE obj)
+{
+ return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_priv_i);
+}
+
+/*
+ * call-seq:
+ * obj.public_methods(all=true) -> array
+ *
+ * Returns the list of public methods accessible to <i>obj</i>. If
+ * the <i>all</i> parameter is set to <code>false</code>, only those methods
+ * in the receiver will be listed.
+ */
+
+VALUE
+rb_obj_public_methods(int argc, VALUE *argv, VALUE obj)
+{
+ return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_pub_i);
}
/*
diff --git a/object.c b/object.c
index 3b7d3e6f5c..720f1bf6b8 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 public and protected methods of
- * <i>obj</i>. This will include all the methods accessible in
- * <i>obj</i>'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 <i>obj</i>. If
- * the <i>all</i> parameter is set to <code>false</code>, 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 <i>obj</i>. If
- * the <i>all</i> parameter is set to <code>false</code>, 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 <i>obj</i>. If
- * the <i>all</i> parameter is set to <code>false</code>, 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: