summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-07 05:52:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-07 05:52:15 +0000
commitcf1a22fdf914f96126f5a8b671dab9a69db236f8 (patch)
treef29f4544c0b908746734dc336209fe13c7850d89 /ext
parentaf01b0fb07af13238cf4a881853d3f8c8787649e (diff)
downloadruby-cf1a22fdf914f96126f5a8b671dab9a69db236f8.tar.gz
* st.c (st_update): table can be unpacked in the callback.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34460 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/-test-/st/numhash/numhash.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/ext/-test-/st/numhash/numhash.c b/ext/-test-/st/numhash/numhash.c
index e186cd43d9..adf3d258b9 100644
--- a/ext/-test-/st/numhash/numhash.c
+++ b/ext/-test-/st/numhash/numhash.c
@@ -57,6 +57,30 @@ numhash_each(VALUE self)
return st_foreach((st_table *)DATA_PTR(self), numhash_i, self) ? Qtrue : Qfalse;
}
+static int
+update_func(st_data_t key, st_data_t *value, st_data_t arg)
+{
+ VALUE ret = rb_yield_values(2, (VALUE)key, (VALUE)*value);
+ switch (ret) {
+ case Qfalse:
+ return ST_STOP;
+ case Qnil:
+ return ST_DELETE;
+ default:
+ *value = ret;
+ return ST_CONTINUE;
+ }
+}
+
+static VALUE
+numhash_update(VALUE self, VALUE key)
+{
+ if (st_update((st_table *)DATA_PTR(self), (st_data_t)key, update_func, 0))
+ return Qtrue;
+ else
+ return Qfalse;
+}
+
void
Init_numhash(void)
{
@@ -66,4 +90,6 @@ Init_numhash(void)
rb_define_method(st, "[]", numhash_aref, 1);
rb_define_method(st, "[]=", numhash_aset, 2);
rb_define_method(st, "each", numhash_each, 0);
+ rb_define_method(st, "update", numhash_update, 1);
}
+