зеркало из https://github.com/github/ruby.git
Cannot `define` from defined `Data` class again
This commit is contained in:
Родитель
c198cf4329
Коммит
cbd82f5250
10
struct.c
10
struct.c
|
@ -384,10 +384,12 @@ setup_data(VALUE subclass, VALUE members)
|
|||
members = struct_set_members(subclass, members);
|
||||
|
||||
rb_define_alloc_func(subclass, struct_alloc);
|
||||
rb_define_singleton_method(subclass, "new", rb_data_s_new, -1);
|
||||
rb_define_singleton_method(subclass, "[]", rb_data_s_new, -1);
|
||||
rb_define_singleton_method(subclass, "members", rb_struct_s_members_m, 0);
|
||||
rb_define_singleton_method(subclass, "inspect", rb_struct_s_inspect, 0); // FIXME: just a separate method?..
|
||||
VALUE sclass = rb_singleton_class(subclass);
|
||||
rb_undef_method(sclass, "define");
|
||||
rb_define_method(sclass, "new", rb_data_s_new, -1);
|
||||
rb_define_method(sclass, "[]", rb_data_s_new, -1);
|
||||
rb_define_method(sclass, "members", rb_struct_s_members_m, 0);
|
||||
rb_define_method(sclass, "inspect", rb_struct_s_inspect, 0); // FIXME: just a separate method?..
|
||||
|
||||
len = RARRAY_LEN(members);
|
||||
for (i=0; i< len; i++) {
|
||||
|
|
|
@ -14,6 +14,8 @@ class TestData < Test::Unit::TestCase
|
|||
|
||||
# Because some code is shared with Struct, check we don't share unnecessary functionality
|
||||
assert_raise(TypeError) { Data.define(:foo, keyword_init: true) }
|
||||
|
||||
assert_not_respond_to(Data.define, :define, "Cannot define from defined Data class")
|
||||
end
|
||||
|
||||
def test_define_edge_cases
|
||||
|
|
Загрузка…
Ссылка в новой задаче