diff --git a/struct.c b/struct.c index 1284fd4aa2..9207c6291d 100644 --- a/struct.c +++ b/struct.c @@ -356,19 +356,14 @@ rb_struct_s_inspect(VALUE klass) * * Examples: * Foo = Struct.new(:a) - * Foo.keyword_init? # => false + * Foo.keyword_init? # => nil * Bar = Struct.new(:a, 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) -{ - if (RTEST(rb_struct_s_keyword_init(klass))) { - return Qtrue; - } else { - return Qfalse; - } -} + +#define rb_struct_s_keyword_init_p rb_struct_s_keyword_init static VALUE setup_struct(VALUE nstr, VALUE members) diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb index 000d229e17..19577266c7 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -144,6 +144,9 @@ module TestStruct struct = @Struct.new(:a, :b, keyword_init: false) assert_equal(false, struct.keyword_init?) + + struct = @Struct.new(:a, :b) + assert_nil(struct.keyword_init?) end def test_initialize