ruby-changes:73499
From: Nobuyoshi <ko1@a...>
Date: Fri, 9 Sep 2022 19:00:16 +0900 (JST)
Subject: [ruby-changes:73499] cfe10e482e (master): [DOC] Update `Struct#new` behavior with `keyword_init: true`
https://git.ruby-lang.org/ruby.git/commit/?id=cfe10e482e From cfe10e482e0657195cadf01f0be72e11b7fb62b4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 9 Sep 2022 18:58:07 +0900 Subject: [DOC] Update `Struct#new` behavior with `keyword_init: true` --- struct.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/struct.c b/struct.c index 7085042b43..1e7294eb5e 100644 --- a/struct.c +++ b/struct.c @@ -471,8 +471,8 @@ rb_struct_define_under(VALUE outer, const char *name, ...) https://github.com/ruby/ruby/blob/trunk/struct.c#L471 * * - May be anonymous, or may have the name given by +class_name+. * - May have members as given by +member_names+. - * - May have initialization via ordinary arguments (the default) - * or via keyword arguments (if <tt>keyword_init: true</tt> is given). + * - May have initialization via ordinary arguments (unless + * <tt>keyword_init: true</tt> is given), or via keyword arguments * * The new subclass has its own method <tt>::new</tt>; thus: * @@ -557,7 +557,7 @@ rb_struct_define_under(VALUE outer, const char *name, ...) https://github.com/ruby/ruby/blob/trunk/struct.c#L557 * By default, the arguments for initializing an instance of the new subclass * are ordinary arguments (not keyword arguments). * With optional keyword argument <tt>keyword_init: true</tt>, - * the new subclass is initialized with keyword arguments: + * the new subclass must be initialized with keyword arguments: * * # Without keyword_init: true. * Foo = Struct.new('Foo', :foo, :bar) @@ -567,6 +567,7 @@ rb_struct_define_under(VALUE outer, const char *name, ...) https://github.com/ruby/ruby/blob/trunk/struct.c#L567 * Bar = Struct.new(:foo, :bar, keyword_init: true) * Bar # => # => Bar(keyword_init: true) * Bar.new(bar: 1, foo: 0) # => #<struct Bar foo=0, bar=1> + * Bar.new(0, 1) # Raises ArgumentError: wrong number of arguments * */ -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/