[DOC] Update Struct#new behavior with keyword_init: true

This commit is contained in:
Nobuyoshi Nakada 2022-09-09 18:58:07 +09:00
parent aff6534e32
commit cfe10e482e
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6

View File

@ -471,8 +471,8 @@ rb_struct_define_under(VALUE outer, const char *name, ...)
* *
* - May be anonymous, or may have the name given by +class_name+. * - May be anonymous, or may have the name given by +class_name+.
* - May have members as given by +member_names+. * - May have members as given by +member_names+.
* - May have initialization via ordinary arguments (the default) * - May have initialization via ordinary arguments (unless
* or via keyword arguments (if <tt>keyword_init: true</tt> is given). * <tt>keyword_init: true</tt> is given), or via keyword arguments
* *
* The new subclass has its own method <tt>::new</tt>; thus: * The new subclass has its own method <tt>::new</tt>; thus:
* *
@ -557,7 +557,7 @@ rb_struct_define_under(VALUE outer, const char *name, ...)
* By default, the arguments for initializing an instance of the new subclass * By default, the arguments for initializing an instance of the new subclass
* are ordinary arguments (not keyword arguments). * are ordinary arguments (not keyword arguments).
* With optional keyword argument <tt>keyword_init: true</tt>, * 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. * # Without keyword_init: true.
* Foo = Struct.new('Foo', :foo, :bar) * Foo = Struct.new('Foo', :foo, :bar)
@ -567,6 +567,7 @@ rb_struct_define_under(VALUE outer, const char *name, ...)
* Bar = Struct.new(:foo, :bar, keyword_init: true) * Bar = Struct.new(:foo, :bar, keyword_init: true)
* Bar # => # => Bar(keyword_init: true) * Bar # => # => Bar(keyword_init: true)
* Bar.new(bar: 1, foo: 0) # => #<struct Bar foo=0, bar=1> * Bar.new(bar: 1, foo: 0) # => #<struct Bar foo=0, bar=1>
* Bar.new(0, 1) # Raises ArgumentError: wrong number of arguments
* *
*/ */