From 19c42c0740145dec1be93c332647f4310ea19918 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 10 Apr 2002 08:45:26 +0000 Subject: * variable.c (rb_obj_remove_instance_variable): raise NameError if specified instance variable is not defined. * variable.c (generic_ivar_remove): modified to check ivar existence. * file.c (rb_file_s_extname): new method based on the proposal (and patch) from Mike Hall. [new] * eval.c (error_handle): default to 1 unless status is set. * eval.c (ruby_options): guard error_handle() with PROT_NONE. * eval.c (ruby_stop): ditto. * math.c (math_acosh): added. [new] * math.c (math_asinh): ditto. * math.c (math_atanh): ditto. * struct.c (rb_struct_each_pair): method added. [new] * class.c (rb_singleton_class): wrong condition; was creating unnecessary singleton class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- struct.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'struct.c') diff --git a/struct.c b/struct.c index 6a2bb640ab..7e97e170f5 100644 --- a/struct.c +++ b/struct.c @@ -333,6 +333,23 @@ rb_struct_each(s) return s; } +static VALUE +rb_struct_each_pair(s) + VALUE s; +{ + VALUE member; + long i; + + member = rb_struct_iv_get(rb_obj_class(s), "__member__"); + if (NIL_P(member)) { + rb_bug("non-initialized struct"); + } + for (i=0; ilen; i++) { + rb_yield(rb_assoc_new(RARRAY(member)->ptr[i], RSTRUCT(s)->ptr[i])); + } + return s; +} + static VALUE rb_struct_to_s(s) VALUE s; @@ -584,6 +601,7 @@ Init_Struct() rb_define_method(rb_cStruct, "length", rb_struct_size, 0); rb_define_method(rb_cStruct, "each", rb_struct_each, 0); + rb_define_method(rb_cStruct, "each_pair", rb_struct_each_pair, 0); rb_define_method(rb_cStruct, "[]", rb_struct_aref, 1); rb_define_method(rb_cStruct, "[]=", rb_struct_aset, 2); rb_define_method(rb_cStruct, "select", rb_struct_select, -1); -- cgit v1.2.1