[#28561] Ruby::DL vs Ruby::FFI — Aston <blackapache512-ticket@...>

Ruby.DL and FFI libraries are great for programmers like me who are not internet programmers, but are more interested in scientific and number processing etc.

11 messages 2010/03/08

[#28686] trunk (26947) build fail with msys/mingw/vista — Jon <jon.forums@...>

I get the following build failure when msysgit's "c:\git\cmd" dir is on PATH.

8 messages 2010/03/16

[#28687] [Bug #2973] rb_bug - Segmentation fault - error.c:213 — rudolf gavlas <redmine@...>

Bug #2973: rb_bug - Segmentation fault - error.c:213

10 messages 2010/03/16

[#28735] [Bug #2982] Ruby tries to link with both openssl and readline — Lucas Nussbaum <redmine@...>

Bug #2982: Ruby tries to link with both openssl and readline

16 messages 2010/03/18

[#28736] [Bug #2983] Ruby (GPLv2 only) tries to link to with readline (now GPLv3) — Lucas Nussbaum <redmine@...>

Bug #2983: Ruby (GPLv2 only) tries to link to with readline (now GPLv3)

10 messages 2010/03/18

[#28907] [Bug #3000] Open SSL Segfaults — Christian Höltje <redmine@...>

Bug #3000: Open SSL Segfaults

19 messages 2010/03/23

[#28924] [Bug #3005] Ruby core dump - [BUG] rb_sys_fail() - errno == 0 — Sebastian YEPES <redmine@...>

Bug #3005: Ruby core dump - [BUG] rb_sys_fail() - errno == 0

10 messages 2010/03/24

[#28954] [Feature #3010] slow require gems in ruby 1.9.1 — Miao Jiang <redmine@...>

Feature #3010: slow require gems in ruby 1.9.1

15 messages 2010/03/24

[#29179] [Bug #3071] Convert rubygems and rdoc to use psych — Aaron Patterson <redmine@...>

Bug #3071: Convert rubygems and rdoc to use psych

10 messages 2010/03/31

[ruby-core:28399] [Bug #2495] Matrix: Vector#each2 should check its argument

From: Marc-Andre Lafortune <redmine@...>
Date: 2010-03-02 07:52:31 UTC
List: ruby-core #28399
Issue #2495 has been updated by Marc-Andre Lafortune.



Hi,

On Mon, Feb 1, 2010 at 10:44 PM, Yusuke ENDOH <mame@tsg.ne.jp> wrote:
> Matz or Keiju, will you give us your opinion?

Ist Keiju is even registered on the ruby-core mailing list?


I'd like to point out an alternate implementation can use #each instead of #[], and at least avoid the non-sensical results on integers. Example:

diff --git a/lib/matrix.rb b/lib/matrix.rb
index d452bf4..f9b2f58 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -1146,8 +1146,10 @@ class Vector
   def each2(v) # :yield: e1, e2
     Vector.Raise ErrDimensionMismatch if size != v.size
     return to_enum(:each2, v) unless block_given?
-    size.times do |i|
-      yield @elements[i], v[i]
+    i = 0
+    v.each do |elem|
+      yield @elements[i], elem
+      i+=1
     end
     self
   end


I'm all for duck typing, as long as we give an idea of what type of "quacking" we're expecting. I would still suggest adding at the beginning of the method:

unless v.respond_to?(:size) && v.respond_to?(:each)
  raise TypeError, "Argument must respond to :size and :each"
end

----------------------------------------
http://redmine.ruby-lang.org/issues/show/2495

----------------------------------------
http://redmine.ruby-lang.org

In This Thread