summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-15 05:20:11 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-15 05:20:11 +0000
commitd738fed4ebcce9231856dc22c07965ab26744af4 (patch)
tree4b4a9bd4c561e3a89f001ebe2f753a9b500c59dc
parent1a42f3683fbd3735c3d217cc4cf31fdc1af1a93e (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-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;
}