From 0ce138263f8bea54e13953167bb1c82794506d02 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Tue, 15 Aug 2006 19:40:25 +0200 Subject: [PATCH] Added Ogg::Vorbis::Comments#shift. --- ext/comments.c | 15 +++++++++++++++ test/test_main.rb | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/ext/comments.c b/ext/comments.c index cdaf576..f7919db 100644 --- a/ext/comments.c +++ b/ext/comments.c @@ -357,6 +357,20 @@ c_merge (VALUE self, VALUE hash) 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")); +} + /* * call-seq: * object <=> other -> -1, 0 or 1 @@ -490,6 +504,7 @@ Init_Comments (VALUE mVorbis) rb_define_method (c, "keys", c_keys, 0); rb_define_method (c, "values", c_values, 0); rb_define_method (c, "merge!", c_merge, 1); + rb_define_method (c, "shift", c_shift, 0); rb_include_module (c, rb_mComparable); rb_define_method (c, "<=>", c_compare, 1); diff --git a/test/test_main.rb b/test/test_main.rb index be81bb8..802c9c5 100644 --- a/test/test_main.rb +++ b/test/test_main.rb @@ -230,4 +230,13 @@ EOF t.comments.values) end end + + def test_shift + Ogg::Vorbis::Tagger.open(OGG_FILE) do |t| + assert_equal(["artist", "Bolt Thrower"], t.comments.shift) + assert_equal(["album", "...For Victory"], t.comments.shift) + assert_equal(["date", "1994"], t.comments.shift) + assert_equal(nil, t.comments.shift) + end + end end -- 2.30.2