diff options
author | hkdnet <satoko.itse@gmail.com> | 2021-07-15 18:14:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-15 18:14:27 +0900 |
commit | 1a637544166eca6b917fb6f32baeb771f4914b7a (patch) | |
tree | 26580d4abc3dffcd881fe0abb5a0500642b0fec2 /struct.c | |
parent | 3ce2bf4d908c5cc80b8c53a21a09cd0d9d8ec26c (diff) | |
download | ruby-1a637544166eca6b917fb6f32baeb771f4914b7a.tar.gz |
struct.c: Add keyword_init? singleton method for StructClass (#4609)
Fixes [Feature #18008]
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -347,6 +347,29 @@ rb_struct_s_inspect(VALUE klass) return inspect; } +/* + * call-seq: + * StructClass.keyword_init? -> true or false + * + * Returns true if the class was initialized with +keyword_init: true+. + * Otherwise returns false. + * + * Examples: + * Foo = Struct.new(:a) + * Foo.keyword_init? # => false + * Bar = Struct.new(:a, keyword_init: true) + * Bar.keyword_init? # => true + */ +static VALUE +rb_struct_s_keyword_init_p(VALUE klass) +{ + if (RTEST(rb_struct_s_keyword_init(klass))) { + return Qtrue; + } else { + return Qfalse; + } +} + static VALUE setup_struct(VALUE nstr, VALUE members) { @@ -359,6 +382,8 @@ setup_struct(VALUE nstr, VALUE members) rb_define_singleton_method(nstr, "[]", rb_class_new_instance_pass_kw, -1); rb_define_singleton_method(nstr, "members", rb_struct_s_members_m, 0); rb_define_singleton_method(nstr, "inspect", rb_struct_s_inspect, 0); + rb_define_singleton_method(nstr, "keyword_init?", rb_struct_s_keyword_init_p, 0); + len = RARRAY_LEN(members); for (i=0; i< len; i++) { VALUE sym = RARRAY_AREF(members, i); |