aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-01-07 18:27:13 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-01-07 18:27:13 +0000
commita6bbdaa4d9b4a90707d0aba4c94c97fe633bb197 (patch)
tree6e520a2e8bc06dad9ecc250d5133bf4fe9c320ee
parentd7520fd7c9845883aa36ec89a673eac4a9209f22 (diff)
downloadpaludis-a6bbdaa4d9b4a90707d0aba4c94c97fe633bb197.tar.gz
paludis-a6bbdaa4d9b4a90707d0aba4c94c97fe633bb197.tar.xz
Ruby Contents is Enumerable.
-rw-r--r--ruby/contents.cc19
-rw-r--r--ruby/contents_TEST.rb3
2 files changed, 11 insertions, 11 deletions
diff --git a/ruby/contents.cc b/ruby/contents.cc
index 6230981..dae7cc0 100644
--- a/ruby/contents.cc
+++ b/ruby/contents.cc
@@ -92,20 +92,19 @@ namespace
/*
* call-seq:
- * entries -> Array
+ * each {|contents_entry| block}
*
- * Gets an array of entries.
+ * Iterate through our entries.
*/
VALUE
- contents_entries(VALUE self)
+ contents_each(VALUE self)
{
Contents::Pointer * ptr;
Data_Get_Struct(self, Contents::Pointer, ptr);
- VALUE result(rb_ary_new());
for (Contents::Iterator i ((*ptr)->begin()), i_end((*ptr)->end()) ; i != i_end; ++i)
- rb_ary_push(result, contents_entry_to_value(*i));
- return result;
+ rb_yield(contents_entry_to_value(*i));
+ return self;
}
VALUE
@@ -194,12 +193,14 @@ namespace
/*
* Document-class: Paludis::Contents
*
- * A package's contents.
+ * A package's contents. Includes Enumerable[http://www.ruby-doc.org/core/classes/Enumerable.html],
+ * but not Comparable.
*/
c_contents = rb_define_class_under(paludis_module(), "Contents", rb_cObject);
+ rb_include_module(c_contents, rb_mEnumerable);
rb_define_singleton_method(c_contents, "new", RUBY_FUNC_CAST(&contents_new), 0);
rb_define_method(c_contents, "initialize", RUBY_FUNC_CAST(&contents_init), 0);
- rb_define_method(c_contents, "entries", RUBY_FUNC_CAST(&contents_entries), 0);
+ rb_define_method(c_contents, "each", RUBY_FUNC_CAST(&contents_each), 0);
rb_define_method(c_contents, "add", RUBY_FUNC_CAST(&contents_add), 1);
/*
@@ -231,7 +232,7 @@ namespace
/*
* Document-class: Paludis::ContentsMiscEntry
-
+ *
* A miscellaneous ContentsEntry
*/
c_contents_misc_entry = rb_define_class_under(paludis_module(), "ContentsMiscEntry", c_contents_entry);
diff --git a/ruby/contents_TEST.rb b/ruby/contents_TEST.rb
index 0bcbc9a..af0d697 100644
--- a/ruby/contents_TEST.rb
+++ b/ruby/contents_TEST.rb
@@ -218,8 +218,7 @@ module Paludis
def test_responds_to
c = get_c
- assert_respond_to c, :add
- assert_respond_to c, :entries
+ [:add, :entries, :each].each {|sym| assert_respond_to c, sym}
end
def test_add