summaryrefslogtreecommitdiff
path: root/eval.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 /eval.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 'eval.c')
-rw-r--r--eval.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index 8a4646e..c39ece1 100644
--- a/eval.c
+++ b/eval.c
@@ -3510,8 +3510,52 @@ static VALUE
rb_mod_method_defined(mod, mid)
VALUE mod, mid;
{
- if (rb_method_boundp(mod, rb_to_id(mid), 1)) {
- return Qtrue;
+ return rb_method_boundp(mod, rb_to_id(mid), 1);
+}
+
+#define VISI_CHECK(x,f) (((x)&NOEX_MASK) == (f))
+
+static VALUE
+rb_mod_public_method_defined(mod, mid)
+ VALUE mod, mid;
+{
+ VALUE klass;
+ ID id = rb_to_id(mid);
+ int noex;
+
+ if (rb_get_method_body(&mod, &id, &noex)) {
+ if (VISI_CHECK(noex, NOEX_PUBLIC))
+ return Qtrue;
+ }
+ return Qfalse;
+}
+
+static VALUE
+rb_mod_private_method_defined(mod, mid)
+ VALUE mod, mid;
+{
+ VALUE klass;
+ ID id = rb_to_id(mid);
+ int noex;
+
+ if (rb_get_method_body(&mod, &id, &noex)) {
+ if (VISI_CHECK(noex, NOEX_PRIVATE))
+ return Qtrue;
+ }
+ return Qfalse;
+}
+
+static VALUE
+rb_mod_protected_method_defined(mod, mid)
+ VALUE mod, mid;
+{
+ VALUE klass;
+ ID id = rb_to_id(mid);
+ int noex;
+
+ if (rb_get_method_body(&mod, &id, &noex)) {
+ if (VISI_CHECK(noex, NOEX_PROTECTED))
+ return Qtrue;
}
return Qfalse;
}
@@ -6152,6 +6196,9 @@ Init_eval()
rb_define_private_method(rb_cModule, "private", rb_mod_private, -1);
rb_define_private_method(rb_cModule, "module_function", rb_mod_modfunc, -1);
rb_define_method(rb_cModule, "method_defined?", rb_mod_method_defined, 1);
+ rb_define_method(rb_cModule, "public_method_defined?", rb_mod_public_method_defined, 1);
+ rb_define_method(rb_cModule, "private_method_defined?", rb_mod_private_method_defined, 1);
+ rb_define_method(rb_cModule, "protected_method_defined?", rb_mod_protected_method_defined, 1);
rb_define_method(rb_cModule, "public_class_method", rb_mod_public_method, -1);
rb_define_method(rb_cModule, "private_class_method", rb_mod_private_method, -1);
rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);