зеркало из https://github.com/github/ruby.git
Revert "Add {Method,UnboundMethod}#{public?,private?,protected?}"
This reverts commit2727815068
and58dc8bf8f1
. Visibility is an attribute of the method entry in a class, not an attribute of the Method object. Fixes [#18729] Fixes [#18751] Fixes [#18435]
This commit is contained in:
Родитель
bfa6a8ddc8
Коммит
ff42e2359b
60
proc.c
60
proc.c
|
@ -40,7 +40,6 @@ struct METHOD {
|
|||
const VALUE iclass;
|
||||
const rb_method_entry_t * const me;
|
||||
/* for bound methods, `me' should be rb_callable_method_entry_t * */
|
||||
rb_method_visibility_t visibility;
|
||||
};
|
||||
|
||||
VALUE rb_cUnboundMethod;
|
||||
|
@ -1664,7 +1663,6 @@ mnew_missing(VALUE klass, VALUE obj, ID id, VALUE mclass)
|
|||
me = rb_method_entry_create(id, klass, METHOD_VISI_UNDEF, def);
|
||||
|
||||
RB_OBJ_WRITE(method, &data->me, me);
|
||||
data->visibility = METHOD_ENTRY_VISI(me);
|
||||
|
||||
return method;
|
||||
}
|
||||
|
@ -1722,7 +1720,6 @@ mnew_internal(const rb_method_entry_t *me, VALUE klass, VALUE iclass,
|
|||
RB_OBJ_WRITE(method, &data->klass, klass);
|
||||
RB_OBJ_WRITE(method, &data->iclass, iclass);
|
||||
RB_OBJ_WRITE(method, &data->me, me);
|
||||
data->visibility = visi;
|
||||
|
||||
return method;
|
||||
}
|
||||
|
@ -1820,7 +1817,6 @@ method_eq(VALUE method, VALUE other)
|
|||
|
||||
if (!rb_method_entry_eq(m1->me, m2->me) ||
|
||||
klass1 != klass2 ||
|
||||
m1->visibility != m2->visibility ||
|
||||
m1->klass != m2->klass ||
|
||||
m1->recv != m2->recv) {
|
||||
return Qfalse;
|
||||
|
@ -1874,7 +1870,6 @@ method_unbind(VALUE obj)
|
|||
RB_OBJ_WRITE(method, &data->klass, orig->klass);
|
||||
RB_OBJ_WRITE(method, &data->iclass, orig->iclass);
|
||||
RB_OBJ_WRITE(method, &data->me, rb_method_entry_clone(orig->me));
|
||||
data->visibility = orig->visibility;
|
||||
|
||||
return method;
|
||||
}
|
||||
|
@ -2390,7 +2385,6 @@ method_clone(VALUE self)
|
|||
RB_OBJ_WRITE(clone, &data->klass, orig->klass);
|
||||
RB_OBJ_WRITE(clone, &data->iclass, orig->iclass);
|
||||
RB_OBJ_WRITE(clone, &data->me, rb_method_entry_clone(orig->me));
|
||||
data->visibility = orig->visibility;
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
@ -2641,7 +2635,6 @@ umethod_bind(VALUE method, VALUE recv)
|
|||
RB_OBJ_WRITE(method, &bound->klass, klass);
|
||||
RB_OBJ_WRITE(method, &bound->iclass, iclass);
|
||||
RB_OBJ_WRITE(method, &bound->me, me);
|
||||
bound->visibility = data->visibility;
|
||||
|
||||
return method;
|
||||
}
|
||||
|
@ -2677,7 +2670,7 @@ umethod_bind_call(int argc, VALUE *argv, VALUE method)
|
|||
VALUE methclass, klass, iclass;
|
||||
const rb_method_entry_t *me;
|
||||
convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me);
|
||||
struct METHOD bound = { recv, klass, 0, me, METHOD_ENTRY_VISI(me) };
|
||||
struct METHOD bound = { recv, klass, 0, me };
|
||||
|
||||
return call_method_data(ec, &bound, argc, argv, passed_procval, RB_PASS_CALLED_KEYWORDS);
|
||||
}
|
||||
|
@ -3354,51 +3347,6 @@ method_super_method(VALUE method)
|
|||
return mnew_internal(me, me->owner, iclass, data->recv, mid, rb_obj_class(method), FALSE, FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* meth.public? -> true or false
|
||||
*
|
||||
* Returns whether the method is public.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
method_public_p(VALUE method)
|
||||
{
|
||||
const struct METHOD *data;
|
||||
TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
|
||||
return RBOOL(data->visibility == METHOD_VISI_PUBLIC);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* meth.protected? -> true or false
|
||||
*
|
||||
* Returns whether the method is protected.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
method_protected_p(VALUE method)
|
||||
{
|
||||
const struct METHOD *data;
|
||||
TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
|
||||
return RBOOL(data->visibility == METHOD_VISI_PROTECTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* meth.private? -> true or false
|
||||
*
|
||||
* Returns whether the method is private.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
method_private_p(VALUE method)
|
||||
{
|
||||
const struct METHOD *data;
|
||||
TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
|
||||
return RBOOL(data->visibility == METHOD_VISI_PRIVATE);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* local_jump_error.exit_value -> obj
|
||||
|
@ -4339,9 +4287,6 @@ Init_Proc(void)
|
|||
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, "public?", method_public_p, 0);
|
||||
rb_define_method(rb_cMethod, "protected?", method_protected_p, 0);
|
||||
rb_define_method(rb_cMethod, "private?", method_private_p, 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);
|
||||
|
@ -4365,9 +4310,6 @@ Init_Proc(void)
|
|||
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, "public?", method_public_p, 0);
|
||||
rb_define_method(rb_cUnboundMethod, "protected?", method_protected_p, 0);
|
||||
rb_define_method(rb_cUnboundMethod, "private?", method_private_p, 0);
|
||||
|
||||
/* Module#*_method */
|
||||
rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1);
|
||||
|
|
|
@ -199,11 +199,6 @@ class TestMethod < Test::Unit::TestCase
|
|||
assert_equal(o.method(:foo), o.method(:foo))
|
||||
assert_equal(o.method(:foo), o.method(:bar))
|
||||
assert_not_equal(o.method(:foo), o.method(:baz))
|
||||
|
||||
class << o
|
||||
private :bar
|
||||
end
|
||||
assert_not_equal(o.method(:foo), o.method(:bar))
|
||||
end
|
||||
|
||||
def test_hash
|
||||
|
@ -330,8 +325,8 @@ class TestMethod < Test::Unit::TestCase
|
|||
def PUBLIC_SINGLETON_TEST.def; end
|
||||
end
|
||||
def test_define_singleton_method_public
|
||||
assert_equal(true, PUBLIC_SINGLETON_TEST.method(:dsm).public?)
|
||||
assert_equal(true, PUBLIC_SINGLETON_TEST.method(:def).public?)
|
||||
assert_nil(PUBLIC_SINGLETON_TEST.dsm)
|
||||
assert_nil(PUBLIC_SINGLETON_TEST.def)
|
||||
end
|
||||
|
||||
def test_define_singleton_method_no_proc
|
||||
|
@ -1197,50 +1192,6 @@ class TestMethod < Test::Unit::TestCase
|
|||
assert_nil(super_method)
|
||||
end
|
||||
|
||||
def test_method_visibility_predicates
|
||||
v = Visibility.new
|
||||
assert_equal(true, v.method(:mv1).public?)
|
||||
assert_equal(true, v.method(:mv2).private?)
|
||||
assert_equal(true, v.method(:mv3).protected?)
|
||||
assert_equal(false, v.method(:mv2).public?)
|
||||
assert_equal(false, v.method(:mv3).private?)
|
||||
assert_equal(false, v.method(:mv1).protected?)
|
||||
end
|
||||
|
||||
def test_unbound_method_visibility_predicates
|
||||
assert_equal(true, Visibility.instance_method(:mv1).public?)
|
||||
assert_equal(true, Visibility.instance_method(:mv2).private?)
|
||||
assert_equal(true, Visibility.instance_method(:mv3).protected?)
|
||||
assert_equal(false, Visibility.instance_method(:mv2).public?)
|
||||
assert_equal(false, Visibility.instance_method(:mv3).private?)
|
||||
assert_equal(false, Visibility.instance_method(:mv1).protected?)
|
||||
end
|
||||
|
||||
class VisibilitySub < Visibility
|
||||
protected :mv1
|
||||
public :mv2
|
||||
private :mv3
|
||||
end
|
||||
|
||||
def test_method_visibility_predicates_with_subclass_visbility_change
|
||||
v = VisibilitySub.new
|
||||
assert_equal(false, v.method(:mv1).public?)
|
||||
assert_equal(false, v.method(:mv2).private?)
|
||||
assert_equal(false, v.method(:mv3).protected?)
|
||||
assert_equal(true, v.method(:mv2).public?)
|
||||
assert_equal(true, v.method(:mv3).private?)
|
||||
assert_equal(true, v.method(:mv1).protected?)
|
||||
end
|
||||
|
||||
def test_unbound_method_visibility_predicates_with_subclass_visbility_change
|
||||
assert_equal(false, VisibilitySub.instance_method(:mv1).public?)
|
||||
assert_equal(false, VisibilitySub.instance_method(:mv2).private?)
|
||||
assert_equal(false, VisibilitySub.instance_method(:mv3).protected?)
|
||||
assert_equal(true, VisibilitySub.instance_method(:mv2).public?)
|
||||
assert_equal(true, VisibilitySub.instance_method(:mv3).private?)
|
||||
assert_equal(true, VisibilitySub.instance_method(:mv1).protected?)
|
||||
end
|
||||
|
||||
def rest_parameter(*rest)
|
||||
rest
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче