ruby-changes:7839
From: yugui <ko1@a...>
Date: Mon, 15 Sep 2008 21:02:52 +0900 (JST)
Subject: [ruby-changes:7839] Ruby:r19360 (trunk): * lib/matrix.rb (Matrix#eql?): fixed .
yugui 2008-09-15 21:02:39 +0900 (Mon, 15 Sep 2008) New Revision: 19360 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19360 Log: * lib/matrix.rb (Matrix#eql?): fixed [ruby-dev:36298]. Reported by an anonymous user. * lib/matrix.rb (Vector#eql?): ditto. * (Matrix#compare_by_row_vectors): takes comparison strategy as an optional parameter. * (Vector#compare_by): ditto. Modified files: trunk/ChangeLog trunk/lib/matrix.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 19359) +++ ChangeLog (revision 19360) @@ -1,3 +1,15 @@ +Mon Sep 15 20:57:00 2008 Yuki Sonoda (Yugui) <yugui@y...> + + * lib/matrix.rb (Matrix#eql?): fixed [ruby-dev:36298]. + Reported by an anonymous user. + + * lib/matrix.rb (Vector#eql?): ditto. + + * (Matrix#compare_by_row_vectors): takes comparison + strategy as an optional parameter. + + * (Vector#compare_by): ditto. + Mon Sep 15 14:34:32 2008 NARUSE, Yui <naruse@r...> * encoding.c (RUBY_MAX_CHAR_LEN): defined. Index: lib/matrix.rb =================================================================== --- lib/matrix.rb (revision 19359) +++ lib/matrix.rb (revision 19360) @@ -410,17 +410,21 @@ other.compare_by_row_vectors(@rows) end - alias eql? == + def eql?(other) + return false unless Matrix === other + + other.compare_by_row_vectors(@rows, :eql?) + end # # Not really intended for general consumption. # - def compare_by_row_vectors(rows) + def compare_by_row_vectors(rows, comparison = :==) return false unless @rows.size == rows.size 0.upto(@rows.size - 1) do |i| - return false unless @rows[i] == rows[i] + return false unless @rows[i].send(comparison, rows[i]) end true end @@ -1200,13 +1204,17 @@ other.compare_by(@elements) end - alias eql? == + def eql?(other) + return false unless Vector === other + + other.compare_by(@elements, :eql?) + end # # For internal use. # - def compare_by(elements) - @elements == elements + def compare_by(elements, comparison = :==) + @elements.send(comparison, elements) end # -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/