aboutsummaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-03 00:31:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-03 00:31:02 +0000
commit042e5013a3bc42a3637aa1646e9fc002436b852f (patch)
tree3cf356117c517f93cf85124578415e30a18ca0de /struct.c
parentccd5c3ddfc69cd007aa807b1fe3c84f06438a01f (diff)
downloadruby-042e5013a3bc42a3637aa1646e9fc002436b852f.tar.gz
struct.c: rb_struct_define_under
* struct.c (rb_struct_define_under): new function to define Struct under the given namespace, not under Struct. [Feature #8264] * ext/etc/etc.c: use rb_struct_define_under. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/struct.c b/struct.c
index 90af2d0568..ebb301701c 100644
--- a/struct.c
+++ b/struct.c
@@ -283,6 +283,25 @@ rb_struct_define(const char *name, ...)
return setup_struct(st, ary);
}
+VALUE
+rb_struct_define_under(VALUE outer, const char *name, ...)
+{
+ va_list ar;
+ VALUE ary;
+ char *mem;
+
+ ary = rb_ary_tmp_new(0);
+
+ va_start(ar, name);
+ while ((mem = va_arg(ar, char*)) != 0) {
+ ID slot = rb_intern(mem);
+ rb_ary_push(ary, ID2SYM(slot));
+ }
+ va_end(ar);
+
+ return setup_struct(rb_define_class_under(outer, name, rb_cStruct), ary);
+}
+
/*
* call-seq:
* Struct.new([class_name] [, member_name]+>) -> StructClass