+static VALUE
+merge_cb (VALUE ar, VALUE self)
+{
+ struct RArray *pair = RARRAY (ar);
+
+ c_aset (self, pair->ptr[0], pair->ptr[1]);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * object.merge!(arg) -> object
+ *
+ * Adds the key-value pairs from *arg* to *object*, overwriting existing
+ * values if a key already existed in *object*.
+ *
+ * Note that *arg*'s each method needs to yield key-value pairs for this
+ * to work. This means that e.g. hashes and Ogg::Vorbis::Comments objects
+ * are supported as arguments.
+ */
+static VALUE
+c_merge (VALUE self, VALUE arg)
+{
+ if (!rb_respond_to (arg, id_each))
+ rb_raise (rb_eArgError, "invalid argument");
+
+ rb_iterate (rb_each, arg, merge_cb, self);
+
+ return self;
+}
+
+/*
+ * call-seq:
+ * object.shift(hash) -> array or nil
+ *
+ * Removes the first key-value pair from *object* and returns it
+ * as the two-item array [key, value].
+ * If *object* is empty, +nil+ is returned.
+ */
+static VALUE
+c_shift (VALUE self)
+{
+ return rb_ary_shift (rb_iv_get (self, "items"));
+}
+