diff options
author | Alan Wu <[email protected]> | 2019-10-29 20:08:01 -0400 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2019-10-31 00:37:53 +0900 |
commit | 4c7f789e942e78ebd3a7e3bf458c6cbe2133d692 (patch) | |
tree | 8affdffdba75380c3e032bbb4be12bbe42f2fb78 /test/ruby/test_struct.rb | |
parent | 6c3ed0d71cb1b59be5b2fbc886b5dd962ab74d35 (diff) |
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`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2634
Diffstat (limited to 'test/ruby/test_struct.rb')
-rw-r--r-- | test/ruby/test_struct.rb | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index ec7728b197..22a6ce8241 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -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) } |