mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
8411f58ed7
commit
2406207cbb
1 changed files with 8 additions and 4 deletions
12
struct.c
12
struct.c
|
@ -475,7 +475,8 @@ rb_struct_define_under(VALUE outer, const char *name, ...)
|
|||
* 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, 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");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue