From de09557fdbeb5648cc66ea5fca28b3d769003ee8 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Thu, 7 Sep 2006 12:57:41 +0200 Subject: [PATCH] Made Ogg::Vorbis::Comments usable standalone, too. --- ext/comments.c | 18 ++++++++++++++++-- test/test_main.rb | 5 +++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ext/comments.c b/ext/comments.c index f7919db..fb3ae82 100644 --- a/ext/comments.c +++ b/ext/comments.c @@ -35,8 +35,8 @@ comments_init (VALUE self, vcedit_state *state) vc = vcedit_comments (state); - items = rb_ary_new2 (vc->comments); - rb_iv_set (self, "items", items); + items = rb_iv_get (self, "items"); + rb_ary_clear (items); for (i = 0; i < vc->comments; i++) { VALUE k, v, pair; @@ -79,6 +79,19 @@ comments_sync (VALUE self, vcedit_state *state) StringValuePtr (pair->ptr[1])); } } +/* + * call-seq: + * Ogg::Vorbis::Comments.new -> object + * + * Creates an Ogg::Vorbis::Comments object. + */ +static VALUE +c_init (VALUE self) +{ + rb_iv_set (self, "items", rb_ary_new ()); + + return self; +} /* * call-seq: @@ -493,6 +506,7 @@ Init_Comments (VALUE mVorbis) c = rb_define_class_under (mVorbis, "Comments", rb_cObject); + rb_define_method (c, "initialize", c_init, 0); rb_define_method (c, "inspect", c_inspect, 0); rb_define_method (c, "clear", c_clear, 0); rb_define_method (c, "delete", c_delete, 1); diff --git a/test/test_main.rb b/test/test_main.rb index a4a1450..817b59f 100644 --- a/test/test_main.rb +++ b/test/test_main.rb @@ -295,4 +295,9 @@ EOF ensure FileUtils.rm_f("test/foo.bar") end + + def test_standalone_comments_object + o = Ogg::Vorbis::Comments.new + assert_equal(o.length, 0); + end end -- 2.30.2