summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-30 08:04:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-30 08:04:32 +0000
commited1881510950af3d8599c1a7dca14d53c35eb348 (patch)
tree2f685ff48cc03c119fe1d059e933834db03c2dae /class.c
parenta2868ff65166b27acbbda4af1b9df84ed3171541 (diff)
* eval.c (rb_mod_public_method_defined, etc.): new methods:
public_method_defined?, private_method_defined?, protected_method_defined? * object.c (rb_obj_public_methods): new method Object#public_methods. * class.c (ins_methods_i): Object#methods should list both public and protected methods. * class.c (rb_class_public_instance_methods): new method Module#public_instance_methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/class.c b/class.c
index fb3ea6a..edd17e1 100644
--- a/class.c
+++ b/class.c
@@ -456,23 +456,26 @@ rb_mod_ancestors(mod)
return ary;
}
+#define VISI_CHECK(x,f) (((x)&NOEX_MASK) == (f))
+
static int
ins_methods_i(key, body, ary)
ID key;
NODE *body;
VALUE ary;
{
- if ((body->nd_noex&(NOEX_PRIVATE|NOEX_PROTECTED)) == 0) {
+ if (!body->nd_body) {
+ rb_ary_push(ary, Qnil);
+ rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
+ }
+ else if (!VISI_CHECK(body->nd_noex, NOEX_PRIVATE)) {
VALUE name = rb_str_new2(rb_id2name(key));
if (!rb_ary_includes(ary, name)) {
- if (!body->nd_body) {
- rb_ary_push(ary, Qnil);
- }
rb_ary_push(ary, name);
}
}
- else if (body->nd_body && nd_type(body->nd_body) == NODE_ZSUPER) {
+ else if (nd_type(body->nd_body) == NODE_ZSUPER) {
rb_ary_push(ary, Qnil);
rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
}
@@ -489,7 +492,7 @@ ins_methods_prot_i(key, body, ary)
rb_ary_push(ary, Qnil);
rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
}
- else if (body->nd_noex & NOEX_PROTECTED) {
+ else if (VISI_CHECK(body->nd_noex, NOEX_PROTECTED)) {
VALUE name = rb_str_new2(rb_id2name(key));
if (!rb_ary_includes(ary, name)) {
@@ -513,7 +516,31 @@ ins_methods_priv_i(key, body, ary)
rb_ary_push(ary, Qnil);
rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
}
- else if (body->nd_noex & NOEX_PRIVATE) {
+ else if (VISI_CHECK(body->nd_noex, NOEX_PRIVATE)) {
+ VALUE name = rb_str_new2(rb_id2name(key));
+
+ if (!rb_ary_includes(ary, name)) {
+ rb_ary_push(ary, name);
+ }
+ }
+ else if (nd_type(body->nd_body) == NODE_ZSUPER) {
+ rb_ary_push(ary, Qnil);
+ rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
+ }
+ return ST_CONTINUE;
+}
+
+static int
+ins_methods_pub_i(key, body, ary)
+ ID key;
+ NODE *body;
+ VALUE ary;
+{
+ if (!body->nd_body) {
+ rb_ary_push(ary, Qnil);
+ rb_ary_push(ary, rb_str_new2(rb_id2name(key)));
+ }
+ else if (VISI_CHECK(body->nd_noex, NOEX_PUBLIC)) {
VALUE name = rb_str_new2(rb_id2name(key));
if (!rb_ary_includes(ary, name)) {
@@ -591,6 +618,18 @@ rb_class_private_instance_methods(argc, argv, mod)
}
VALUE
+rb_class_public_instance_methods(argc, argv, mod)
+ int argc;
+ VALUE *argv;
+ VALUE mod;
+{
+ VALUE option;
+
+ rb_scan_args(argc, argv, "01", &option);
+ return method_list(mod, RTEST(option), ins_methods_pub_i);
+}
+
+VALUE
rb_obj_singleton_methods(argc, argv, obj)
int argc;
VALUE *argv;