summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--struct.c17
2 files changed, 19 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 7f0d3c68141..2c027ef85d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Jul 15 14:13:02 2013 Masaki Matsushita <glass.saga@gmail.com>
+
+ * struct.c (rb_struct_each_pair): use rb_yield_values(2, key, value)
+ instead of rb_yield(rb_assoc_new(key, value)) if rb_block_arity()
+ is greater than 1.
+
Mon Jul 15 13:46:26 2013 Tanaka Akira <akr@fsij.org>
* bignum.c: Add static assertions.
diff --git a/struct.c b/struct.c
index 5dc5e73ae83..90af2d05687 100644
--- a/struct.c
+++ b/struct.c
@@ -524,10 +524,19 @@ rb_struct_each_pair(VALUE s)
RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size);
members = rb_struct_members(s);
- for (i=0; i<RSTRUCT_LEN(s); i++) {
- VALUE key = rb_ary_entry(members, i);
- VALUE value = RSTRUCT_GET(s, i);
- rb_yield(rb_assoc_new(key, value));
+ if (rb_block_arity() > 1) {
+ for (i=0; i<RSTRUCT_LEN(s); i++) {
+ VALUE key = rb_ary_entry(members, i);
+ VALUE value = RSTRUCT_GET(s, i);
+ rb_yield_values(2, key, value);
+ }
+ }
+ else {
+ for (i=0; i<RSTRUCT_LEN(s); i++) {
+ VALUE key = rb_ary_entry(members, i);
+ VALUE value = RSTRUCT_GET(s, i);
+ rb_yield(rb_assoc_new(key, value));
+ }
}
return s;
}