ruby-changes:7840
From: yugui <ko1@a...>
Date: Mon, 15 Sep 2008 21:09:45 +0900 (JST)
Subject: [ruby-changes:7840] Ruby:r19361 (ruby_1_8): * lib/matrix.rb (Matrix#eql?): fixed .
yugui 2008-09-15 21:09:30 +0900 (Mon, 15 Sep 2008) New Revision: 19361 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19361 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: branches/ruby_1_8/ChangeLog branches/ruby_1_8/lib/matrix.rb Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 19360) +++ ruby_1_8/ChangeLog (revision 19361) @@ -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 10:28:10 2008 Yuki Sonoda (Yugui) <yugui@y...> * test/matrix/test_matrix.rb (setup): typo. Index: ruby_1_8/lib/matrix.rb =================================================================== --- ruby_1_8/lib/matrix.rb (revision 19360) +++ ruby_1_8/lib/matrix.rb (revision 19361) @@ -402,17 +402,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 @@ -1087,13 +1091,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/