@@ -3227,6 +3227,51 @@ method_super_method(VALUE method)
32273227 return mnew_internal (me , me -> owner , iclass , data -> recv , mid , rb_obj_class (method ), FALSE, FALSE);
32283228}
32293229
3230+ /*
3231+ * call-seq:
3232+ * meth.public? -> true or false
3233+ *
3234+ * Returns whether the method is public.
3235+ */
3236+
3237+ static VALUE
3238+ method_public_p (VALUE method )
3239+ {
3240+ const struct METHOD * data ;
3241+ TypedData_Get_Struct (method , struct METHOD , & method_data_type , data );
3242+ return RBOOL (METHOD_ENTRY_VISI (data -> me ) == METHOD_VISI_PUBLIC );
3243+ }
3244+
3245+ /*
3246+ * call-seq:
3247+ * meth.protected? -> true or false
3248+ *
3249+ * Returns whether the method is protected.
3250+ */
3251+
3252+ static VALUE
3253+ method_protected_p (VALUE method )
3254+ {
3255+ const struct METHOD * data ;
3256+ TypedData_Get_Struct (method , struct METHOD , & method_data_type , data );
3257+ return RBOOL (METHOD_ENTRY_VISI (data -> me ) == METHOD_VISI_PROTECTED );
3258+ }
3259+
3260+ /*
3261+ * call-seq:
3262+ * meth.private? -> true or false
3263+ *
3264+ * Returns whether the method is private.
3265+ */
3266+
3267+ static VALUE
3268+ method_private_p (VALUE method )
3269+ {
3270+ const struct METHOD * data ;
3271+ TypedData_Get_Struct (method , struct METHOD , & method_data_type , data );
3272+ return RBOOL (METHOD_ENTRY_VISI (data -> me ) == METHOD_VISI_PRIVATE );
3273+ }
3274+
32303275/*
32313276 * call-seq:
32323277 * local_jump_error.exit_value -> obj
@@ -4163,6 +4208,9 @@ Init_Proc(void)
41634208 rb_define_method (rb_cMethod , "source_location" , rb_method_location , 0 );
41644209 rb_define_method (rb_cMethod , "parameters" , rb_method_parameters , 0 );
41654210 rb_define_method (rb_cMethod , "super_method" , method_super_method , 0 );
4211+ rb_define_method (rb_cMethod , "public?" , method_public_p , 0 );
4212+ rb_define_method (rb_cMethod , "protected?" , method_protected_p , 0 );
4213+ rb_define_method (rb_cMethod , "private?" , method_private_p , 0 );
41664214 rb_define_method (rb_mKernel , "method" , rb_obj_method , 1 );
41674215 rb_define_method (rb_mKernel , "public_method" , rb_obj_public_method , 1 );
41684216 rb_define_method (rb_mKernel , "singleton_method" , rb_obj_singleton_method , 1 );
@@ -4186,6 +4234,9 @@ Init_Proc(void)
41864234 rb_define_method (rb_cUnboundMethod , "source_location" , rb_method_location , 0 );
41874235 rb_define_method (rb_cUnboundMethod , "parameters" , rb_method_parameters , 0 );
41884236 rb_define_method (rb_cUnboundMethod , "super_method" , method_super_method , 0 );
4237+ rb_define_method (rb_cUnboundMethod , "public?" , method_public_p , 0 );
4238+ rb_define_method (rb_cUnboundMethod , "protected?" , method_protected_p , 0 );
4239+ rb_define_method (rb_cUnboundMethod , "private?" , method_private_p , 0 );
41894240
41904241 /* Module#*_method */
41914242 rb_define_method (rb_cModule , "instance_method" , rb_mod_instance_method , 1 );
0 commit comments