Project

General

Profile

Feature #11689 ยป 0001-Add-Method-visibility-and-UnboundMethod-visibility.patch

yui-knk (Kaneko Yuichiro), 11/15/2015 04:53 AM

View differences:

proc.c
}
/*
* call-seq:
* meth.visibility -> symbol
*
* Returns a symbol (:public, :private, or :protected).
*/
static VALUE
rb_method_visibility(VALUE method)
{
const struct METHOD *data;
VALUE sym;
TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
switch(METHOD_ENTRY_VISI(data->me)) {
case METHOD_VISI_UNDEF:
case METHOD_VISI_PUBLIC: sym = ID2SYM(rb_intern("public")); break;
case METHOD_VISI_PRIVATE: sym = ID2SYM(rb_intern("private")); break;
case METHOD_VISI_PROTECTED: sym = ID2SYM(rb_intern("protected")); break;
default: UNREACHABLE;
}
return sym;
}
/*
* call-seq:
* local_jump_error.exit_value -> obj
*
......
rb_define_method(rb_cMethod, "source_location", rb_method_location, 0);
rb_define_method(rb_cMethod, "parameters", rb_method_parameters, 0);
rb_define_method(rb_cMethod, "super_method", method_super_method, 0);
rb_define_method(rb_cMethod, "visibility", rb_method_visibility, 0);
rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
rb_define_method(rb_mKernel, "public_method", rb_obj_public_method, 1);
rb_define_method(rb_mKernel, "singleton_method", rb_obj_singleton_method, 1);
......
rb_define_method(rb_cUnboundMethod, "source_location", rb_method_location, 0);
rb_define_method(rb_cUnboundMethod, "parameters", rb_method_parameters, 0);
rb_define_method(rb_cUnboundMethod, "super_method", method_super_method, 0);
rb_define_method(rb_cUnboundMethod, "visibility", rb_method_visibility, 0);
/* Module#*_method */
rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1);
test/ruby/test_method.rb
assert_nil(m, Feature9781)
end
def test_visibility_method
v = Visibility.new
assert_equal(:public, v.method(:mv1).visibility)
assert_equal(:private, v.method(:mv2).visibility)
assert_equal(:protected, v.method(:mv3).visibility)
end
def test_visibility_method_unbound
assert_equal(:public, Visibility.instance_method(:mv1).visibility)
assert_equal(:private, Visibility.instance_method(:mv2).visibility)
assert_equal(:protected, Visibility.instance_method(:mv3).visibility)
end
def rest_parameter(*rest)
rest
end
    (1-1/1)