mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
01b723ba6d
commit
e51dca2596
2 changed files with 7 additions and 0 deletions
3
struct.c
3
struct.c
|
@ -551,6 +551,9 @@ rb_struct_s_def(int argc, VALUE *argv, VALUE klass)
|
|||
tbl = RHASH_TBL(rest);
|
||||
for (i=0; i<argc; i++) {
|
||||
VALUE mem = rb_to_symbol(argv[i]);
|
||||
if (rb_is_attrset_sym(mem)) {
|
||||
rb_raise(rb_eArgError, "invalid struct member: %"PRIsVALUE, mem);
|
||||
}
|
||||
if (st_insert(tbl, mem, Qtrue)) {
|
||||
rb_raise(rb_eArgError, "duplicate member: %"PRIsVALUE, mem);
|
||||
}
|
||||
|
|
|
@ -60,6 +60,10 @@ module TestStruct
|
|||
assert_equal(1, o.a)
|
||||
end
|
||||
|
||||
def test_attrset_id
|
||||
assert_raise(ArgumentError) { Struct.new(:x=) }
|
||||
end
|
||||
|
||||
def test_members
|
||||
klass = @Struct.new(:a)
|
||||
o = klass.new(1)
|
||||
|
|
Loading…
Reference in a new issue