From 2406207cbba15384868255d75dd3b8cb71b60e85 Mon Sep 17 00:00:00 2001 From: k0kubun Date: Tue, 12 Dec 2017 15:12:05 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- struct.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/struct.c b/struct.c index e025228828..3a21ec8dbf 100644 --- a/struct.c +++ b/struct.c @@ -475,7 +475,8 @@ rb_struct_define_under(VALUE outer, const char *name, ...) * Customer.new("Dave", "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, VALUE klass) 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, VALUE arg) 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 VALUE *argv, VALUE self) 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"); }