ruby-changes:66796
From: Nobuyoshi <ko1@a...>
Date: Thu, 15 Jul 2021 23:11:35 +0900 (JST)
Subject: [ruby-changes:66796] 3e7a7fb28a (master): Make Struct#keyword_init? return nil by default [Feature #18008]
https://git.ruby-lang.org/ruby.git/commit/?id=3e7a7fb28a From 3e7a7fb28a9a6a9544e1e49dfab51122ccfdac3f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 15 Jul 2021 21:33:39 +0900 Subject: Make Struct#keyword_init? return nil by default [Feature #18008] --- struct.c | 15 +++++---------- test/ruby/test_struct.rb | 3 +++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/struct.c b/struct.c index 1284fd4..9207c62 100644 --- a/struct.c +++ b/struct.c @@ -356,19 +356,14 @@ rb_struct_s_inspect(VALUE klass) https://github.com/ruby/ruby/blob/trunk/struct.c#L356 * * 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 000d229..1957726 100644 --- a/test/ruby/test_struct.rb +++ b/test/ruby/test_struct.rb @@ -144,6 +144,9 @@ module TestStruct https://github.com/ruby/ruby/blob/trunk/test/ruby/test_struct.rb#L144 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/