1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Make Struct#keyword_init? return nil by default [Feature #18008]

This commit is contained in:
Nobuyoshi Nakada 2021-07-15 21:33:39 +09:00
parent 33bea3bdff
commit 3e7a7fb28a
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 8 additions and 10 deletions

View file

@ -356,19 +356,14 @@ rb_struct_s_inspect(VALUE klass)
* *
* Examples: * Examples:
* Foo = Struct.new(:a) * Foo = Struct.new(:a)
* Foo.keyword_init? # => false * Foo.keyword_init? # => nil
* Bar = Struct.new(:a, keyword_init: true) * Bar = Struct.new(:a, keyword_init: true)
* Bar.keyword_init? # => true * Bar.keyword_init? # => true
* Baz = Struct.new(:a, keyword_init: false)
* Baz.keyword_init? # => false
*/ */
static VALUE
rb_struct_s_keyword_init_p(VALUE klass) #define rb_struct_s_keyword_init_p rb_struct_s_keyword_init
{
if (RTEST(rb_struct_s_keyword_init(klass))) {
return Qtrue;
} else {
return Qfalse;
}
}
static VALUE static VALUE
setup_struct(VALUE nstr, VALUE members) setup_struct(VALUE nstr, VALUE members)

View file

@ -144,6 +144,9 @@ module TestStruct
struct = @Struct.new(:a, :b, keyword_init: false) struct = @Struct.new(:a, :b, keyword_init: false)
assert_equal(false, struct.keyword_init?) assert_equal(false, struct.keyword_init?)
struct = @Struct.new(:a, :b)
assert_nil(struct.keyword_init?)
end end
def test_initialize def test_initialize