mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 17:14:01 +02:00
Allow only one argument for keyword_init struct
``` irb(main):001:0> RUBY_VERSION => "2.6.5" irb(main):002:0> S = Struct.new(:foo, keyword_init: true) => S(keyword_init: true) irb(main):003:0> S.new({foo: 23424}, 234) # I don't think this is intentional => #<struct S foo=23424> irb(main):004:0> ``` Tightening this up should inform users when they are confused about whether a struct is `keyword_init`.
This commit is contained in:
parent
6c3ed0d71c
commit
4c7f789e94
Notes:
git
2019-10-31 00:38:28 +09:00
2 changed files with 2 additions and 1 deletions
|
@ -105,6 +105,7 @@ module TestStruct
|
|||
@Struct.new("KeywordInitFalse", :a, :b, keyword_init: false)
|
||||
|
||||
assert_raise(ArgumentError) { @Struct::KeywordInitTrue.new(1, 2) }
|
||||
assert_raise(ArgumentError) { @Struct::KeywordInitTrue.new({a: 100}, 2) }
|
||||
assert_nothing_raised { @Struct::KeywordInitFalse.new(1, 2) }
|
||||
assert_nothing_raised { @Struct::KeywordInitTrue.new(a: 1, b: 2) }
|
||||
assert_raise(ArgumentError) { @Struct::KeywordInitTrue.new(1, b: 2) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue