From db14bfe4ea7f5ab0ece77d4109bb0fb13ef9fe54 Mon Sep 17 00:00:00 2001 From: yugui Date: Mon, 15 Sep 2008 12:02:39 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 ++++++++++++ lib/matrix.rb | 20 ++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 91ededdaa4..78366c4874 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Mon Sep 15 20:57:00 2008 Yuki Sonoda (Yugui) + + * 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 * encoding.c (RUBY_MAX_CHAR_LEN): defined. diff --git a/lib/matrix.rb b/lib/matrix.rb index ca8cae36e0..c672ee5198 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -410,17 +410,21 @@ class Matrix 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 @@ class Vector 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 #