diff --git a/ChangeLog b/ChangeLog index c242392fc0..8041f2b9ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Mar 3 16:14:24 2010 Yukihiro Matsumoto + + * lib/matrix.rb (Vector#each): make Vector enumerable. + [ruby-core:28405] + Wed Mar 3 14:28:23 2010 Yukihiro Matsumoto * array.c (rb_ary_select_bang): select! removes all elements for diff --git a/lib/matrix.rb b/lib/matrix.rb index d452bf459e..a008182c42 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -1081,6 +1081,7 @@ end # class Vector include ExceptionForMatrix + include Enumerable #INSTANCE CREATION @@ -1140,6 +1141,16 @@ class Vector # ENUMERATIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #++ + # + # Iterate over the elements of this vector + # + def each + return to_enum(:each) unless block_given? + @elements.each do |i| + yield i + end + end + # # Iterate over the elements of this vector and +v+ in conjunction. #