From: Yukihiro Matsumoto Date: 2010-03-02T17:29:46+09:00 Subject: [ruby-core:28401] Re: [Bug #2495] Matrix: Vector#each2 should check its argument Hi, In message "Re: [ruby-core:28399] [Bug #2495] Matrix: Vector#each2 should check its argument" on Tue, 2 Mar 2010 16:52:31 +0900, Marc-Andre Lafortune writes: |On Mon, Feb 1, 2010 at 10:44 PM, Yusuke ENDOH 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: Accepted, but I prefer each_with_index though. |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 If we change the policy and decide to add respond_to? check to methods, we add infinite number of checks everywhere (exaggerated of course). I am not in a mood to make such big change during 1.9.2 period. matz.