ruby-changes:49065
From: k0kubun <ko1@a...>
Date: Wed, 13 Dec 2017 00:22:03 +0900 (JST)
Subject: [ruby-changes:49065] k0kubun:r61182 (trunk): struct.c: don't explain implementation details
k0kubun 2017-12-13 00:12:05 +0900 (Wed, 13 Dec 2017) New Revision: 61182 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61182 Log: struct.c: don't explain implementation details of keyword_init option. [DOC] [ci skip] It's implemented to take Hash, but it's just implementation detail and it's intended to behave in the same way as keyword arguments (for :keyword_init option too). Also I unified coding style of r61137 with other places. Modified files: trunk/struct.c Index: struct.c =================================================================== --- struct.c (revision 61181) +++ struct.c (revision 61182) @@ -475,7 +475,8 @@ rb_struct_define_under(VALUE outer, cons https://github.com/ruby/ruby/blob/trunk/struct.c#L475 * Customer.new("Dave", "123 Main") * #=> #<struct Customer name="Dave", address="123 Main"> * - * If keyword_init: true option is given, .new takes Hash instead of Array. + * If keyword_init: true option is given, .new takes keyword arguments instead + * of normal arguments. * * Customer = Struct.new(:name, :address, keyword_init: true) * #=> Customer @@ -536,7 +537,8 @@ rb_struct_s_def(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/struct.c#L537 rb_get_kwargs(argv[argc-1], keyword_ids, 0, 1, kwargs); --argc; keyword_init = kwargs[0]; - } else { + } + else { keyword_init = Qfalse; } @@ -599,7 +601,8 @@ struct_hash_set_i(VALUE key, VALUE val, https://github.com/ruby/ruby/blob/trunk/struct.c#L601 args->unknown_keywords = rb_ary_new(); } rb_ary_push(args->unknown_keywords, key); - } else { + } + else { rb_struct_modify(args->self); RSTRUCT_SET(args->self, i, val); } @@ -627,7 +630,8 @@ rb_struct_initialize_m(int argc, const V https://github.com/ruby/ruby/blob/trunk/struct.c#L630 rb_raise(rb_eArgError, "unknown keywords: %s", RSTRING_PTR(rb_ary_join(arg.unknown_keywords, rb_str_new2(", ")))); } - } else { + } + else { if (n < argc) { rb_raise(rb_eArgError, "struct size differs"); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/