Skip to content

Commit cfe10e4

Browse files
committed
[DOC] Update Struct#new behavior with keyword_init: true
1 parent aff6534 commit cfe10e4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

struct.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ rb_struct_define_under(VALUE outer, const char *name, ...)
471471
*
472472
* - May be anonymous, or may have the name given by +class_name+.
473473
* - May have members as given by +member_names+.
474-
* - May have initialization via ordinary arguments (the default)
475-
* or via keyword arguments (if <tt>keyword_init: true</tt> is given).
474+
* - May have initialization via ordinary arguments (unless
475+
* <tt>keyword_init: true</tt> is given), or via keyword arguments
476476
*
477477
* The new subclass has its own method <tt>::new</tt>; thus:
478478
*
@@ -557,7 +557,7 @@ rb_struct_define_under(VALUE outer, const char *name, ...)
557557
* By default, the arguments for initializing an instance of the new subclass
558558
* are ordinary arguments (not keyword arguments).
559559
* With optional keyword argument <tt>keyword_init: true</tt>,
560-
* the new subclass is initialized with keyword arguments:
560+
* the new subclass must be initialized with keyword arguments:
561561
*
562562
* # Without keyword_init: true.
563563
* Foo = Struct.new('Foo', :foo, :bar)
@@ -567,6 +567,7 @@ rb_struct_define_under(VALUE outer, const char *name, ...)
567567
* Bar = Struct.new(:foo, :bar, keyword_init: true)
568568
* Bar # => # => Bar(keyword_init: true)
569569
* Bar.new(bar: 1, foo: 0) # => #<struct Bar foo=0, bar=1>
570+
* Bar.new(0, 1) # Raises ArgumentError: wrong number of arguments
570571
*
571572
*/
572573

0 commit comments

Comments
 (0)